简体   繁体   中英

How to retrieve the Zend_Config used by Zend_Application?

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']).

Zend_Registry::set('config', new Zend_Config($this->getOptions()));

是你所需要的全部。

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
}

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