简体   繁体   中英

accessing the getOptions() of Zend_Application_Bootstrap_Bootstrap

I'm using the default Zend_Application design pattern which loads a zend config ini file automatically in the application bootstrap and I need to ini file's variables across many models and controllers.

Right now, I'm solving it by settings the config object as a key into Zend_Registry :

protected function _initConfig()
{
    $config = new Zend_Config($this->getOptions());
    Zend_Registry::set('config', $config);
}

Generally, I don't like using Zend_Registry , as it doesn't offer code auto complete in my IDE, and it's hard to keep track on what I have in the registry namespace.

Is there another way to access the Zend_Application's config ini?

In a controller you should be able to do:

$this->getInvokeArg('bootstrap')->getOptions();

to access the config. For models you really should be passing in the options you need. Otherwise your only choice is really the registry.

You could always initialise it as needed yourself with

$options = new Zend_Config_Ini('/path/to/config.ini',
                               'config');

Wich is pretty much what the bootstrap does for you. Then you would have autocomplete on $options. But you would have to initialise it everytime you need it. I think modifying your code to suit autocomplete is not the greatest idea ever. But this is personnal.

If I am not mistaken with Zend Studio 8/9 (maybe 7) you DO have autocomplete even for objects returned by Zend_Registry::get() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM