Yii2如何防止任何小部件的资产捆绑自动加载? [英] Yii2 How to prevent autoloading of assetsbundle of any widget?

查看:85
本文介绍了Yii2如何防止任何小部件的资产捆绑自动加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用\ yii \ jui \ AutoComplete

I am using \yii\jui\AutoComplete

它会自动加载JuiAssets.有什么办法可以防止加载JuiAssets文件?我想使用自己的文件版本.在Yii Framework的先前版本中,我们可以选择阻止加载任何小部件的关联的css和js文件.

It automatically loads the JuiAssets. Is there any way to prevent loading files of JuiAssets? I want to use my own version of files. In the previous version of Yii Framework, we had option to prevent loading the associated css and js files of any widget.

是否可以在不编辑其核心文件的情况下更改任何jui Widget的AssetBundle?

Is there any way to change the AssetBundle for any jui Widget, without editing its core files?

推荐答案

是的,您可以轻松地自定义任何AssetBundle以满足您的需求:

Yes, you can easily customize any AssetBundle to fit your needs:

1)通过应用程序配置:

return [
    'components' => [
        'assetManager' => [
            'bundles' => [
                'yii\jui\JuiAsset' => [
                    'sourcePath' => null, // do not publish the bundle
                    'js' => [
                        // replace published js file here
                    ],
                ],
            ],
        ],
    ],
];

2)您可以在运行时通过assetManager组件执行相同的操作:

2) You can do the same at runtime through assetManager component:

Yii::$app->assetManager->bundles['yii\jui\JuiAsset'] = [
    'sourcePath' => null,
    'js' => [...],
];

官方文档:

  • Customizing Asset Bundles
  • assetManager component

请注意,此提交中已更改了注册jQuery UI组件的逻辑.因此,没有单独的资产捆绑包可用于自动完成等.它们都使用yii\jui\JuiAsset.

Note that logic for registering jQuery UI components was changed in this commit. So there is no separate asset bundle for Autocomplete, etc. They all use yii\jui\JuiAsset.

这篇关于Yii2如何防止任何小部件的资产捆绑自动加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆