2015-10-10 10 views
5

में कस्टम फ़ंक्शन का उपयोग करें yii2 परिसंपत्ति प्रबंधक में 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 
] 

सीएसएस भाग में 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

संबंधित मुद्दे