How I Get Language From Url

Hi

I create multi language site.

How can I set language from url. I dont want set language in each controller. I create CommonController and other controllers extends from it. In this controller set language


Yii::$app->language = Yii::$app->getRequest()->getQueryParam('language');

I think this method wrong

How can i do this better or right?

my example config


'rules' => [

				'<language:(az|en)>/'=>'site/',

				'<language:(az|en)>/about'=>'site/about',

				'<language:(az|en)>/creation'=>'site/creation',

				'<language:(az|en)>/multimedia'=>'site/multimedia',

				'<language:(az|en)>/press'=>'site/press',

			],

I use a behaviour, which I have named ConfigBehavior.

I use this behavior to set and update various app parameters, such as language.

For language I set a default language, then listen for the $_GET request to change it.




namespace common\behaviors;


use Yii;

use yii\base\BootstrapInterface;

use yii\base\Application;

use frontend\models\Language;


class ConfigBehavior implements BootstrapInterface

{

    public function bootstrap($app)

    {

	$app->on(Application::EVENT_BEFORE_REQUEST, function () {


            // do stuff


        });

    }

}



In my config file (common):




    'bootstrap' => [

	'common\\behaviors\\ConfigBehavior',

        'common\\behaviors\\LanguageBehavior',

    ],



I also have LanguageBehavior, which fetches the correct translations from the database.

Class load in bootstrap don’t see


Yii::$app->getRequest()->getQueryParam('language');

or i dont understand. Please help

Backslider,




 'bootstrap' => [

        'common\\behaviors\\ConfigBehavior',

        'common\\behaviors\\LanguageBehavior',

    ],



What is this bootstrap parameter?

Would you rather not attach behaviors with ‘as …’?

Is the approach above documented in guide?