Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework - Reading Application.ini values from a Controller

I am trying to store my Google Maps API Key in my application.ini file, and I would like to be able to read it from my controller whenever its needed. How can I go about reading values from the application.ini from my controller?

Thanks!

like image 416
Ryan Avatar asked Mar 29 '10 14:03

Ryan


2 Answers

This article might help you out. The author explains how to retrieve gmail connection params from the application.ini file.

You might want to try:

$bootstrap = $this->getInvokeArg('bootstrap');
$aConfig = $bootstrap->getOptions();
googleMapsKey = $aConfig['your_resource']['your_key'];
like image 171
Thomas Avatar answered Oct 26 '22 04:10

Thomas


I tend to do this in the bootstrap, and then as Gordon mentions toss it in the registry. You can then get it anywhere out of the registry.

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

Also, to his point, the controller would tend to be the wrong place for it, unless you are accessing the API with multiple keys, I guess, but even then you should be able to place the logic in the model to select a key from the registry.

like image 24
whoughton Avatar answered Oct 26 '22 03:10

whoughton