2014-11-04 5 views
26

Wie Titel, ich möchte nicht mit bootstrap.css und bootstrap.js. Ich versuche mit:Yii2 deaktivieren Bootstrap Js, JQuery und CSS

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

Es bootstrap.css entfernen, aber bootstrap.js nicht entfernen. Jemand kann mir helfen?

Antwort

66

In web.php Konfigurationsdatei den folgenden Code in Komponenten Array hinzufügen:

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

umfassender sein:

um Css (bootstrap.css) zu deaktivieren:

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

um JS (bootstrap.js) zu deaktivieren:

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

, um alle von ihnen JQuery (jquery.js) deaktiviert

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

Um zu deaktivieren zu haben:

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

    ], 
], 

UPDATE

Als Soju in den Kommentaren erwähnt, wäre eine weitere alternative Möglichkeit, diese Dateien in AppAsset Klasse werden zu deaktivieren, die in ./assets/ befindet, dann die folgenden Zeilen entfernen:

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

danke soviel :) – taratula

+1

Warum mich bedeutet dies geben: 'Ungültige Anruf - yii \ base \ InvalidCallException Einstellung schreibgeschützte Eigenschaft: yii \ web \ Anwendung :: assetManager'? –

+0

Wie würde ich dies in Yii v1.1.15 erreichen? –

7

Für alle, die „Invalid Anruf bekommt "Fehler müssen Sie Alis Antwort auf 'Komponenten' in $ config Variable in app/config/web.php Eg hinzufügen

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

Danke, das hat das Problem gelöst. –

+0

Dies gilt nur für die Basisvorlage. – MeV

5

Auf AppAsset.php Datei hinzufügen:

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

Dies ist eine sauberere Option als das Ändern von Konfigurationsdateien und kann verwendet werden, um Bootstrap von Themen zurückzusetzen – paulus