Php 在assetmanager中使用自定义函数
如何在yii2 assetmanager中使用Php 在assetmanager中使用自定义函数,php,yii2,Php,Yii2,如何在yii2 assetmanager中使用Yii::$app->session['somename'] class AppAsset extends AssetBundle{ public function getLang() { $currentLang = Yii::$app->session['lang']; if ($currentLang == 'fa' || $currentLang == 'ar') { return 'RTL'; }
Yii::$app->session['somename']
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
]
如何在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
?您可以这样做
.. other functions
public function init() {
$this->setupAssets();
parent::init();
}
protected function setupAssets() {
$lang = $this->getLang();
$this->css[] = "css/myfile.$lang.css";
}