仅在模块中加载 Yii Bootstrap [英] loading Yii Bootstrap in a module only
本文介绍了仅在模块中加载 Yii Bootstrap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试仅在管理模块中加载 Yii Bootstrap 扩展,但它不起作用.我假设我需要预先加载它或以某种方式启动它...谢谢!
I'm try to load the Yii Bootstrap extension in the admin module only but it's not working. I'm assuming I need to preload it or initiate it somehow... Thanks!
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;
}
}
推荐答案
有 4 种不同的方法可以做到这一点:
There are 4 different ways to do this:
将配置添加到应用程序的配置中 (protected/config/main.php):
'modules'=>array(
'admin'=>array(
'preload'=>array('bootstrap'),
'components'=>array(
'bootstrap'=>array(
'class'=>'ext.bootstrap.components.Bootstrap'
)
),
// ... other modules ...
)
在 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
}
在 init
中预加载的另一种方式:
Preload in init
another way:
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');
}
在 init
中预加载的另一种方式:
Preload in init
yet another way:
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();
}
这篇关于仅在模块中加载 Yii Bootstrap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文