仅在模块中加载Yii Bootstrap

kee*_*eeg 5 yii yii-extensions

我尝试仅在管理模块中加载Yii Bootstrap扩展,但它不起作用.我假设我需要预先加载或以某种方式启动它...谢谢!

    class AdminModule extends CWebModule
    {
        public function init()
        {
            // import the module-level models and components
            $this->setImport(array(
                'admin.models.*',
                'admin.components.*',
                'ext.bootstrap.components.Bootstrap',
            ));
        }

        public function beforeControllerAction($controller, $action)
        {
            if(parent::beforeControllerAction($controller, $action))
            {
                         $this->layout = 'admin';                
                         return true;
            }
            else
                return false;
        }
    }
Run Code Online (Sandbox Code Playgroud)

boo*_*dev 10

有4种不同的方法可以做到这一点:

  1. 将配置添加到应用程序的配置(protected/config/main.php):

    'modules'=>array(
        'admin'=>array(
            'preload'=>array('bootstrap'),
            'components'=>array(
                'bootstrap'=>array(
                    'class'=>'ext.bootstrap.components.Bootstrap'
            )
        ),
    // ... other modules ...
    )    
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在以下位置预加载init:

    public function init()
    {
        // import the module-level models and components
        $this->setImport(array(
            'admin.models.*',
            'admin.components.*',
            // 'ext.bootstrap.components.Bootstrap', // this will go to app config for components
        ));
        Yii::app()->getComponent('bootstrap');// this does the loading
    }
    
    Run Code Online (Sandbox Code Playgroud)
  3. init另一种方式预加载:

    public function init()
    {
        // import the module-level models and components
        $this->setImport(array(
            'admin.models.*',
            'admin.components.*',
        ));
    
        $this->configure(array(
                'components'=>array(
                    'bootstrap'=>array(
                        'class'=>'ext.bootstrap.components.Bootstrap'
                    )
                )
        ));
        $this->getComponent('bootstrap');
    }
    
    Run Code Online (Sandbox Code Playgroud)
  4. init另一种方式预加载:

    public function init()
    {
        // import the module-level models and components
        $this->setImport(array(
            'admin.models.*',
            'admin.components.*',
        ));
    
        $this->configure(array(
                'preload'=>array('bootstrap'),
                'components'=>array(
                    'bootstrap'=>array(
                        'class'=>'ext.bootstrap.components.Bootstrap'
                    )
                )
        ));
        $this->preloadComponents();
    }
    
    Run Code Online (Sandbox Code Playgroud)