Brandon_R
Brandon_R

Reputation: 121

Get Loaded Config In Controller

How do i get the already loaded options in the controller file in a zend framework installation without creating a new Zend_Config([ ** ]); instance.

Upvotes: 5

Views: 3235

Answers (2)

takeshin
takeshin

Reputation: 50638

Once Zend_Application reads application.ini, the values are stored in bootstrap.

You may access them anywhere, without accessing 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 may also use $this->getInvokeArg('bootstrap');

Upvotes: 6

Iznogood
Iznogood

Reputation: 12843

I am not sure at all what you are asking but are you asking how to use configs set in application.ini from a controller? If so you should load that config in Zend_Registry in your bootstrap and then retrieve it in your controller.

So in bootstrap.php

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

The in your Controller

  $myConfig = Zend_Registry::get('config');

Upvotes: 4

Related Questions