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;
}
}
There are 4 different ways to do this:
Add the configuration to the app's configuration (protected/config/main.php):
'modules'=>array(
'admin'=>array(
'preload'=>array('bootstrap'),
'components'=>array(
'bootstrap'=>array(
'class'=>'ext.bootstrap.components.Bootstrap'
)
),
// ... other modules ...
)
Preload it in the 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
}
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');
}
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();
}
When you configure the following in the main config (protected/config/main.php), example as:
'admin' => array(
'preload'=>array('bootstrap'),
'components'=>array(
'bootstrap' => array(
'class' => 'bootstrap.components.Bootstrap',
'responsiveCss' => true,
),
),
)
Then, you can using component as
$bootstrap = $this->getModule()->bootstrap; // with $this is a current controller.
To define this module component to main component, you must to set Component in init() of Module class:
// Set main component `bootstrap` instead of CController->getModule()->bootstrap
app()->setComponent('bootstrap', $this->bootstrap);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With