Tuesday, April 2, 2013

Zend Accessing your configuration data that's stored in application.ini

Zend Accessing your configuration data that's stored in application.ini




Zend Accessing your configuration data that's stored in application.ini

Zend_Application will read the data in your application.ini and make it available from your bootstrap's getOptions() method. It then sets the bootstrap as a parameter in the front controller. Note that the top level keys are all normalised to lowercase too.

You can then retrieve the options in a number of ways.

In the controller you can do this:


public function someAction()
{
$bootstrap = $this->getInvokeArg('bootstrap');
$options = $bootstrap->getOptions();
}



Outside of the controller you can do this:
$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
$options = $bootstrap->getOptions();




One downside is that $options is a nested array, and not a Zend_Config object. If you prefer to work with a Zend_Config object you need to create it yourself as Zend_Application discards the one it creates. The easiest way to do this is to create a new method in your bootstrap to create the Zend_Config object and store to the registry. 


protected function _initConfig()
{
$config = new Zend_Config($this->getOptions());
Zend_Registry::set('config', $config);
return $config;
}



You can then get at your config data wherever you need it. Try not to depend too much on Zend_Registry keys though, as it can make testing harder.


Important Links: Zend Developer, Zend Freelancer, Zend Programmer, Zend, Zend Framework,Zend Development.Hope you have enjoyed the post ! 
any more idea about the same ? let me know by comments !


Know More About :
PHP Freelancing India

Reactions:

0 comments:

Post a Comment

Any Questions or Suggestions ?

About

Professional & Experienced Freelance Developer From India, Technologist, Software Engineer, internet marketer and Open Sources Developer with experience in Finance, Telecoms and the Media. Contact Me for freelancing projects.

Enter your email address:

Delivered by FeedBurner

PHP Freelancer India - Google+