我创建了一个基本的 zend 框架项目,并在那里添加了几个额外的模块。 在每个模块上,我决定为其制作单独的配置文件。我关注了网上的一些资源,正如它所建议的,我将以下代码放在其引导类(而不是应用程序引导类)上
class Custom_Bootstrap extends Zend_Application_Module_Bootstrap {
protected function _bootstrap()
{
$_conf = new Zend_Config_Ini(APPLICATION_PATH . "/modules/" . $this->getModuleName() . "/configs/application.ini", APPLICATION_ENV);
$this->_options = array_merge($this->_options, $_conf->toArray());
parent::_bootstrap();
}
}
它甚至不起作用,它给出了一个错误。
Strict Standards: Declaration of Custom_Bootstrap::_bootstrap() should be compatible with that of Zend_Application_Bootstrap_BootstrapAbstract::_bootstrap() in xxx\application\modules\custom\Bootstrap.php on line 2
不要重写引导方法,只需将模块配置为资源即可:
class Custom_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initConfig()
{
$config = new Zend_Config_Ini(APPLICATION_PATH . "/modules/" . $this->getModuleName() . "/configs/application.ini", APPLICATION_ENV);
$this->_options = array_merge($this->_options, $config->toArray());
return $this->_options;
}
}
这将在模块引导时自动运行。
查看
Zend_Application_Bootstrap_BootstrapAbstract
的源代码,_bootstrap
的声明如下:
protected function _bootstrap($resource = null)
{
...
}
因此,您只需将覆盖更改为如下所示:
protected function _bootstrap($resource = null)
{
$_conf = new Zend_Config_Ini(APPLICATION_PATH . "/modules/" . $this->getModuleName() . "/configs/application.ini", APPLICATION_ENV);
$this->_options = array_merge($this->_options, $_conf->toArray());
parent::_bootstrap($resource);
}