5

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

skaffman
  • 398,947
  • 96
  • 818
  • 769
Brandon_R
  • 121
  • 2
  • 6

2 Answers2

6

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
  • 49,108
  • 32
  • 120
  • 164
4

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
  • 12,447
  • 3
  • 26
  • 44
  • 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 Aug 24 '10 at 16:00
  • 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 Aug 24 '10 at 16:09
  • No, it's an incorrect answer. The bootstrap loads config automatically, you don't do it yourself... – Chris KL Sep 19 '12 at 01:42