2015-10-10 8 views
5

yii2 assetmanagerでYii::$app->session['somename']をどのように使用しますか?assetmanagerでカスタム機能を使用

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を呼びますか?

答えて

1

あなたは私が何を探しています。この

.. other functions 

public function init() { 
    $this->setupAssets(); 
    parent::init(); 
} 

protected function setupAssets() { 
    $lang = $this->getLang(); 
    $this->css[] = "css/myfile.$lang.css"; 
} 
+0

のようにそれを行うことができます!完璧! – mohsen

関連する問題