0

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 {

    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();  
    }   
}

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

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

6 Comments

But I need to merge the new settings with the new one
You can still do that in the same way - I've added your array merge to my code example.
You are merging in $this -> _options, and returning $config... Are you sure its correct... wait I try first
no it didn't work. what i tried was, caused a error and wrote in the module specific application.ini's development stage to not show any errors, where as in the default application.ini, it is configured to show all error is development environment
Okay, that is a completely different problem. Both your code and my code simply setup the config file - you need to do stuff with it if you want its contents to affect your application. I'm not sure how easy it would be to get ZF to treat your config as a module-specific application.ini, and it sounds like this is what you want. Can you give a practical example of the things you want to set in this config file?
|
0

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);  
    }

2 Comments

So you now have your subclass's method defined as protected function _bootstrap($resource = null) and you still get the error? What version of ZF are you using? Can you have a look in Zend_Application_Module_Bootstrap to see how _bootstrap is declared?
i am using the latest, 1.11.9

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.