如何在yii2 assetmanager中使用Yii::$app->session['somename']
?
如何在assetmanager中访问某些功能?
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
]
如何在css部分中调用getLang
?
答案 0 :(得分:1)
你可以这样做
.. other functions
public function init() {
$this->setupAssets();
parent::init();
}
protected function setupAssets() {
$lang = $this->getLang();
$this->css[] = "css/myfile.$lang.css";
}