D
D
Dmitry2017-10-06 01:46:38
Yii
Dmitry, 2017-10-06 01:46:38

How to include BootstrapPluginAsset in a separate module?

Goodnight.
A third-party theme is installed on the site so that bootstrap does not interfere, I turned it off completely in config/web.php

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

But the admin requires bootstrap. The admin panel is made a separate module.
I created a configuration file in the module, included it in AdminModule.php
public function init()
     {
         parent::init();
         Yii::configure($this, require __DIR__ . '/config/config.php');
     }

Contents of config.php
return [
    'id' => 'admin',
    'name' => 'TestName',
    'components' => [
        'assetManager' => [
            'class' => yii\web\AssetManager::className(),
            'bundles' => [
                'yii\bootstrap\BootstrapAsset' => [
                    'sourcePath' => '@bower/bootstrap/dist',
                    'css' => ['css/bootstrap.min.css']
                ],
                'yii\bootstrap\BootstrapPluginAsset' => [
                    'sourcePath' => '@bower/bootstrap/dist',
                    'js' => ['js/bootstrap.min.js']
                ]
            ]
        ]
    ]
];

The result is "0"...
How to include bootstrap in a module? What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Максим Федоров, 2017-10-06
@slo_nik

Результата и не может быть в текущем варианте, по сути дела Вы подключаете AssetManager c бутсрапом как компонент текущего модуля, а используется AssetManager приложения. Для решения задачи Вы можете применить один из вариантов:
1. При инициализации модуля заменить AssetManager используемый View на необходимый Вам, например так:

$assetManager = new \yii\web\AssetManager([
    'bundles' => [
        'yii\bootstrap\BootstrapAsset' => [
            'sourcePath' => '@bower/bootstrap/dist',
            'css' => ['css/bootstrap.min.css']
        ],
        'yii\bootstrap\BootstrapPluginAsset' => [
            'sourcePath' => '@bower/bootstrap/dist',
            'js' => ['js/bootstrap.min.js']
        ]
    ]
]);
Yii::$app->view->setAssetManager($assetManager);

2. При инициализации модуля переконфигурировать AssetManager приложения

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question