Tag: Zend_Application
Main Config with Zend_Application
by Daniel on Nov.02, 2009, under Programming
Mainly a note to myself, but it’s handy to know.
When you instanciate Zend_Application, you provide it with a path to the config file (Or an instance if you’re feelin’ kinky) Zend_Application loads this into a Zend_Config object and does it’s bit with it.
What’s less obvious is how to retrieve that config from within a Zend_Controller_Action::method().
My solution until recently was to have an _initConfig() in my bootstrap class that read in the file again, and stored the instance in a Zend_Registry entry. However I think I cracked the “proper” way or “better” way to do it.
<?php
class MyController extends Zend_Controller_Action
{
/**
* @var array The application configuration
* @access protected
*/
protected $_config;
/**
* Init
*
* Retrieve and assign the application configuration
*
* @access public
* @return null
*/
public function init()
{
$this->_config = Zend_Controller_Front::getInstance()
->getParam( 'bootstrap' )
->getOptions();
}
}
?>
Edit: In that particular example there is actually an instance of Zend_Controller_Front closer to hand, you could use $this->_frontController. But I’ll stick with ::getInstance() for the example since since it gets the job done.