在assetmanager中使用自定义功能


use custom function in assetmanager

如何在yii2assetmanager中使用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
 ]

如何在css部分调用getLang ?

你可以这样做

.. other functions
public function init() {
    $this->setupAssets();
    parent::init();
}
protected function setupAssets() {
    $lang = $this->getLang();
    $this->css[] = "css/myfile.$lang.css";
}