Override Yii2 assetManager config in controller

懵懂的女人 提交于 2019-12-01 21:08:11

You should modify Yii::$app->assetManager->bundles (Yii::$app->assetManager is an object, not an array), e.g.

Yii::$app->assetManager->bundles = [
    'yii\jui\JuiAsset' => [
        'css' => ['themes/dot-luv/jquery-ui.css'],
    ],
];

Or if you want to keep other bundles config :

Yii::$app->assetManager->bundles['yii\jui\JuiAsset'] = [
    'css' => ['themes/dot-luv/jquery-ui.css'],
];

You are going about this all wrong, you want to change the JUI theme for 1 controller alone because of a few controls. You are applying 2 css files to different parts of the website that have the potential to change styles in the layouts too. The solution you found works but it is incredibly bad practice.

If you want to change just some controls do it the proper way by using JUI scopes. Here are some links that will help you:
http://www.filamentgroup.com/lab/using-multiple-jquery-ui-themes-on-a-single-page.html
http://jqueryui.com/download/

In this way you are making the website easier to maintain and you do not create a bigger problem for the future than you what solve.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!