2015-10-10 5 views
5

Wie verwenden Sie Yii::$app->session['somename'] in yii2 Assetmanager?Verwenden Sie benutzerdefinierte Funktion in Assetmanager

Wie Zugriff auf einige Funktionen im 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 
] 

Wie rufen getLang in css Teil?

Antwort

1

Sie tun können, es so

.. other functions 

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

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

das ist, was ich suche! perfekt!!! – mohsen

Verwandte Themen