Problem setting Module specific configuration file
I create a basic zend framwework projects and added couple of extra modules there. On, each module, I decided to make seperate configurations files for it. I followed some resources on the net, and as it suggest, I placed the following code on the its bootstrap class (not the applications bootstrap class)
class Custom_Bootstrap extends Zend_Application_Module_Bootstrap {
protec开发者_C百科ted 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();
}
}
Its not even working, its gives a error.
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
Don't override the bootstrap method, just make your module config a resource:
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;
}
}
this will be run automatically when the module is bootstrapped.
Looking at the source code of Zend_Application_Bootstrap_BootstrapAbstract
, the declaration of _bootstrap
looks like this:
protected function _bootstrap($resource = null)
{
...
}
So you just need to change your override to look like this:
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);
}
精彩评论