Use custom function in asset management agent

How to use Yii::$app->session['somename'] in yii2 propertymanager?

How to access some function in the PropertyManager?

 class AppAsset extends AssetBundle{ public function getLang() { $currentLang = Yii::$app->session['lang']; if ($currentLang == 'fa' || $currentLang == 'ar') { return 'RTL'; } else { return 'LTR'; } } public $lang; public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ 'css/iconSprite.min.css', // how call getLang here ] 

How to call getLang in css part?

+5
source share
1 answer

You can do it like this:

 .. other functions public function init() { $this->setupAssets(); parent::init(); } protected function setupAssets() { $lang = $this->getLang(); $this->css[] = "css/myfile.$lang.css"; } 
+1
source

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


All Articles