Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use custom function in assetmanager

Tags:

php

yii2

How use Yii::$app->session['somename'] in yii2 assetmanager?

How make access some function in 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
 ]

How call getLang in css part?

like image 437
Mohsen Avatar asked Nov 10 '22 03:11

Mohsen


1 Answers

You can do it like this

.. other functions

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

protected function setupAssets() {
    $lang = $this->getLang();
    $this->css[] = "css/myfile.$lang.css";
}
like image 200
Jap Mul Avatar answered Nov 14 '22 20:11

Jap Mul