Download the configuration in the controller

How to get already loaded parameters in the controller file in setting the zend framework without creating a new Zend_Config ([**]); instance.

+5
source share
2 answers

As soon as it Zend_Applicationreads application.ini, the values ​​are stored in the bootstrap.

You can access them anywhere, without access to the disk or using the registry:

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

$options = $bootstrap->getOptions();

In the controller you can also use $this->getInvokeArg('bootstrap');

+6
source

, , , , 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');
+4

All Articles