views:

21

answers:

2

Hello guys,

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

A: 

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');
Iznogood
oh, i thought the config was automatically loaded by the framework, so i just needed the method to get it in the controller.Zend has like 10 different ways to do the same thing, i just wanted to make sure im not duplicating functionality. Thansk.s
Brandon_R
The way I posted is the right way for sure. How about accepting my answer? Read up on how it works here http://stackoverflow.com/faq. And welcome to stackoverflow.
Iznogood
A: 

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');

takeshin