2

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?

aporat
  • 5,922
  • 5
  • 32
  • 54

2 Answers2

4

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.

Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
1

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().

Aurelio De Rosa
  • 21,856
  • 8
  • 48
  • 71
Iznogood
  • 12,447
  • 3
  • 26
  • 44