5

如何在不创建新 Zend_Config([ ** ]) 的情况下在 zend 框架安装中获取控制器文件中已加载的选项;实例。

4

2 回答 2

6

一旦Zend_Application读取application.ini,值将存储在引导程序中。

您可以在任何地方访问它们,无需访问磁盘或使用注册表:

$front = Zend_Controller_Front::getInstance();
$bootstrap = $front->getParam('bootstrap');
if (null === $bootstrap) {
    throw new My_Exception('Unable to find bootstrap');
}

$options = $bootstrap->getOptions();

在控制器中,您还可以使用$this->getInvokeArg('bootstrap');

于 2010-08-24T20:54:17.690 回答
4

我完全不确定您在问什么,但您是在问如何从控制器使用 application.ini 中设置的配置?如果是这样,您应该在引导程序的 Zend_Registry 中加载该配置,然后在控制器中检索它。

所以在 bootstrap.php

  protected function _initConfig() {
        $config = new Zend_Config_Ini("../application/configs/application.ini");
        Zend_Registry::set('config', $config);
    }

在你的控制器中

  $myConfig = Zend_Registry::get('config');
于 2010-08-24T15:22:24.667 回答