2015-10-10 12 views
5

Yii2 assetmanager içinde Yii::$app->session['somename'] nasıl kullanılır?assetmanager öğesinde özel işlev kullanın

Varlık yönetiminde erişim nasıl yapılır?

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 parçasında getLang nasıl aranır?

cevap

1
Sen gibi yapabilirsin

bu

.. other functions 

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

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

i arıyorum ne olduğunu! mükemmel!!! – mohsen

İlgili konular