我尝试仅在管理模块中加载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;
}
}
答案 0 :(得分:10)
有4种不同的方法可以做到这一点:
将配置添加到应用程序的配置( 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
另一种方式预加载:
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
预加载另一种方式:
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();
}
答案 1 :(得分:2)
在主配置(protected / config / main.php)中配置以下内容时,示例为:
'admin' => array(
'preload'=>array('bootstrap'),
'components'=>array(
'bootstrap' => array(
'class' => 'bootstrap.components.Bootstrap',
'responsiveCss' => true,
),
),
)
然后,您可以使用组件
$bootstrap = $this->getModule()->bootstrap; // with $this is a current controller.
要将此模块组件定义为主组件,必须在Module类的init()中设置Component:
// Set main component `bootstrap` instead of CController->getModule()->bootstrap
app()->setComponent('bootstrap', $this->bootstrap);
答案 2 :(得分:1)
真正有效的代码: 在你的模块init函数中只需粘贴以下代码:
Yii::setPathOfAlias('bootstrap', Yii::getPathOfAlias('ext.bootstrap'));
Yii::app()->setComponent('bootstrap', array('class'=>'bootstrap.components.Bootstrap'));
答案 3 :(得分:0)
protected/config/main.php
'modules'=>array(
'admin'=>array(
'preload'=>array('bootstrap'),
'components'=>array(
'bootstrap'=>array(
'class'=>'ext.bootstrap.components.Bootstrap'
)
),
)
在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
}
如果不起作用,请粘贴您的网址 进入该文件,您正在使用bootstrap
<link rel="stylesheet" type="text/css" href="/pojects/fcorginal/assets/b2e88ad5/bootstrap/css/bootstrap.min.css" />