Bootstrap中包含了豐富的Web組件,根據這些組件,可以快速的搭建一個漂亮、功能完備的網站,但是有時候我們網站前臺并不需要Bootstrap,只要管理后臺使用Bootstrap,那么該如何單獨為一個module加載Bootstrap呢?
這里有4種方法來實現這個:
1.在應用的配置文件protected/config/main.php中添加如下內容:
- 'modules'=>array(
- 'admin'=>array(
- 'preload'=>array('<span class='wp_keywordlink_affiliate'><a href="http://lxy.me/tag/bootstrap" title="查看 bootstrap 中的全部文章" target="_blank">bootstrap</a></span>'),
- 'components'=>array(
- '<span class='wp_keywordlink_affiliate'><a href="http://lxy.me/tag/bootstrap" title="查看 bootstrap 中的全部文章" target="_blank">bootstrap</a></span>'=>array(
- 'class'=>'ext.bootstrap.components.Bootstrap'
- )
- ),
- // ...其他模塊...
- )
2.在模塊初始化時加載,代碼如下:
- 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
- }
3.模塊初始化加載的另一種方法:
- 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');
- }
4.模塊加載時的另一種方法,代碼如下:
- 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();
- }
新聞熱點
疑難解答