How I Get Language From Url


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' => [







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' => [




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

Class load in bootstrap don’t see


or i dont understand. Please help


 'bootstrap' => [




What is this bootstrap parameter?

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

Is the approach above documented in guide?