Zend framework 如何检索Zend_应用程序使用的Zend_配置?
我正在迁移我的应用程序以使用Zend_应用程序进行引导。我曾经将Zend_配置作为$registry的键 现在我不知道如何再以这种方式使用它(无需重新加载配置文件)。Zend framework 如何检索Zend_应用程序使用的Zend_配置?,zend-framework,configuration,Zend Framework,Configuration,我正在迁移我的应用程序以使用Zend_应用程序进行引导。我曾经将Zend_配置作为$registry的键 现在我不知道如何再以这种方式使用它(无需重新加载配置文件)。 我知道可以使用$application->getOptions(),但这给了我一个数组,我必须将代码中$config像对象一样使用的地方($config->services->storage)更改为像数组一样使用的地方($config['services']['storage'])。Zend_应用程序只使用(并存储)config.
我知道可以使用$application->getOptions(),但这给了我一个数组,我必须将代码中$config像对象一样使用的地方($config->services->storage)更改为像数组一样使用的地方($config['services']['storage'])。Zend_应用程序只使用(并存储)config.ini文件,如调用“
newZend_应用程序(ENV,…/app.ini)”的第二个参数所示代码>'作为数组。要将其存储为对象,必须重新解析它
您可以在引导程序中添加一个函数,并将其存储到注册表中
<?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
}
这就是你所需要的
Zend_Registry::set('config', new Zend_Config($this->getOptions()));