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!
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'];
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With