Access Session or Yii in Configuration File

I want to access a session or Yii::$appin a configuration file, for example ( config/main.phpor config/main-local.php)!
Is this possible or not?
I want to check the session and make some style available!

'components' => [
    'assetManager' => [
        'assetMap' => [
            'r.css' => Yii::$app->session['lang'] ? 'css/styleltr.css' : 'css/stylertl.css' ,
        ],
    ],

or how to do something like this in propertymanager ????

+4
source share
2 answers

You cannot access a user session in your configuration file. But you can use the conditional expression in your layout and register different assets based on session values.

+2
source

try to access what you need this way

 \Yii::$app->getAssetManager()->assetMap; 
0
source

Source: https://habr.com/ru/post/1611077/


All Articles