php Yii2 禁用 Bootstrap Js、JQuery 和 CSS

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26734385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:01:58  来源:igfitidea点击:

Yii2 disable Bootstrap Js, JQuery and CSS

phptwitter-bootstrapyii2yii-extensions

提问by taratula

Same as title, i don't want using bootstrap.css and bootstrap.js. I try using:

与标题相同,我不想使用 bootstrap.css 和 bootstrap.js。我尝试使用:

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],
    ],
],

It remove bootstrap.css but can't remove bootstrap.js. Somebody can help me?

它删除 bootstrap.css 但不能删除 bootstrap.js。有人可以帮助我吗?

回答by Ali MasudianPour

In web.phpconfig file add the following code into components array:

web.php配置文件中,将以下代码添加到 components 数组中:

'assetManager' => [
        'bundles' => [
            'yii\bootstrap\BootstrapPluginAsset' => [
                'js'=>[]
            ],
        ],
    ],

To be more comprehensive:

更全面:

in order to disable Css (bootstrap.css):

为了禁用 Css (bootstrap.css):

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],
    ],
],

in order to disable JS (bootstrap.js):

为了禁用 JS (bootstrap.js):

'assetManager' => [
    'bundles' => [
        'yii\bootstrap\BootstrapPluginAsset' => [
            'js'=>[]
        ],
    ],
],

in order to disable JQuery (jquery.js)

为了禁用 JQuery (jquery.js)

'assetManager' => [
    'bundles' => [
        'yii\web\JqueryAsset' => [
            'js'=>[]
        ],
    ],
],

In order to have all of them disabled:

为了让所有这些都被禁用:

'assetManager' => [
    'bundles' => [
        'yii\web\JqueryAsset' => [
            'js'=>[]
        ],
        'yii\bootstrap\BootstrapPluginAsset' => [
            'js'=>[]
        ],
        'yii\bootstrap\BootstrapAsset' => [
            'css' => [],
        ],

    ],
],


UPDATE

更新

As Sojumentioned in comments, another alternative way would be disabling these files in AppAssetclass, which is located in ./assets/, then remove the following lines:

正如Soju在评论中提到的,另一种替代方法是在AppAsset位于 中的类中禁用这些文件./assets/,然后删除以下行:

public $depends = [
   'yii\web\YiiAsset',              #REMOVE
   'yii\bootstrap\BootstrapAsset',  #REMOVE
];

回答by PanPipes

For anyone that gets "Invalid Call" errors you have to add Ali's answer to 'components' in $config variable in app/config/web.phpE.g.

对于任何收到“无效调用”错误的人,您必须将 Ali 的答案添加到 $config 变量中的“组件”中,app/config/web.php例如

'components' => [
    'assetManager' => [
        'bundles' => [
            'yii\web\JqueryAsset' => [
                'js'=>[]
            ],
            'yii\bootstrap\BootstrapPluginAsset' => [
                'js'=>[]
            ],
            'yii\bootstrap\BootstrapAsset' => [
                'css' => []
            ]
        ]
    ],
    ...
],

回答by Francesco Loddo

On AppAsset.php file add this:

在 AppAsset.php 文件中添加:

public function init()
{
    parent::init();
    // resetting BootstrapAsset to not load own css files
    \Yii::$app->assetManager->bundles['yii\bootstrap\BootstrapAsset'] = [
        'css' => [],
        'js' => []
    ];
}