views:

232

answers:

2

I'm migrating my app to use Zend_Application for bootstrap. I used to have the Zend_Config as a key for my $registry.

Now I don't know how to use it this way anymore (without having to reload the config file). I know it's possible to use $application->getOptions(), but that gives my an array and I would have to change everywhere in my code where $config is used like an object ($config->services->storage) to array-like ($config['services']['storage']).

+1  A: 

Zend_Application only uses (and stores) the config.ini file, as given in the second parameter of the call to 'new Zend_Application(ENV, '.../app.ini');' as an array. To be able to store it as an object, you'll have to re-parse it.

You can add a function into the bootstrap to do so, and store it into the registry,

<?php
// in 'class Bootstrap extends Zend_Application_Bootstrap_Bootstrap'

protected function _initConfig()
{
    // config
    //#Zend_Registry::set('config', $this->getOptions());  // as an array

    $ZFOptions      = array(); // could be: 'allowModifications'=>true
    $section        = 'production';  // or from the environment
    $configFilename = APPLICATION_PATH .'/configs/application.ini';
    $config = new Zend_Config_Ini($configFilename, $section, $ZFOptions);
    Zend_Registry::set('config', $config);  // as an object
}
Alister Bulman
+3  A: 
Zend_Registry::set('config', new Zend_Config($this->getOptions()));

is all you need.

Benjamin Cremer