1

我正在尝试从模块中包含 yii 引导程序。我想将它保存在 /modules/myModule/extensions/bootstrap 和主配置之外的所有配置参数中。可能吗?

目前在 myModule init 我做

$this->setImport(array(
'myModule.models.*',
'myModule.components.*',
'myModule.extensions.yiistrap.helpers.TbHtml',
'myModule.extensions.bootstrap.components.*',
'myModule.extensions.bootstrap.widgets.*'
));


if (!Yii::app()->hasComponent('bootstrap')) {
Yii::setPathOfAlias('bootstrap', dirname(__FILE__) . '/extensions/bootstrap');
Yii::createComponent('bootstrap.components.Bootstrap')->init();
Yii::app()->bootstrap->register();
}
}

它适用于某些小部件,但对于大多数我得到错误

Property "CWebApplication.bootstrap" is not defined.
4

1 回答 1

0

您需要设置应用程序引导组件,这应该可以工作:

Yii::setPathOfAlias('bootstrap', dirname(__FILE__) . '/extensions/bootstrap');
$bootstrap = Yii::createComponent('bootstrap.components.Bootstrap');
$bootstrap->init();
Yii::app()->bootstrap = $bootstrap;
$bootstrap->register();

将配置传递给引导程序:

$config = array(
    'class' => 'bootstrap.components.Bootstrap',
    'option1' => ...
);
$bootstrap = Yii::createComponent($config);
于 2013-07-12T10:53:39.633 回答