Zend Framework - reading Application.ini values ​​from the controller

I am trying to save my Google Maps API API in the application.ini file, and I would like to be able to read it from my controller whenever necessary. How can I read values ​​from an .ini application from my controller?

Thank!

+5
source share
3 answers

Or through FrontController

// bootstrap
$front->setParam('GMapsApiKey', 123456);

// controller
$this->getFrontController()->getParam('GMapsApiKey');

or registry:

// bootstrap
Zend_Registry::set('GMapsApiKey', '123456');

// controller
Zend_Registry::get('GMapsApiKey');

However, since access to the Google Maps APIs is what happens in the model, your controller does not need to know the API key.

+3
source

This article can help you. The author explains how to get the gmail connection settings from the application.ini file.

, :

$bootstrap = $this->getInvokeArg('bootstrap');
$aConfig = $bootstrap->getOptions();
googleMapsKey = $aConfig['your_resource']['your_key'];
+5

I try to do it in bootstrap, and then, as Gordon says, throws it into the registry. You can get it anywhere from the registry.

$this->config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV);
Zend_Registry::set('config', $this->config);

In addition, in his opinion, the controller will have the wrong place for it, unless you get access to the API with several keys, I think, but even then you should be able to put the logic in the model to select the key from the registry.

+5
source

All Articles