I have a few constants that I'll need to define for my application, for example, SITE_KEY which would contain a random key for salt passwords.
I'm not sure where I should define those, though. I thought of placing them in public/index.php but that seems a bit messy. Is there a specific place where they should go, according to Zend or something?
Thanks
EDIT
I'm trying to do it this way: In my application.ini
I have this:
siteglobal.sitekey = "test"
and in my bootstrap.php
file:
protected function _initGlobals()
{
$config = $this->getOptions();
define('SITE_KEY', $config['siteglobal']['sitekey']);
}
Still, this isn't working, when I try to echo SITE_KEY in my controller like this:
echo SITE_KEY;
It doesn't show anything. Any ideas?
In my application, I'm combining both Haim's and Yeroon's approaches. I'm storing application constants in my application.ini
, then parsing them in the Bootstrap
and putting them into Zend_Registry
.
So, in the application.ini
constants.site_key = my_site_key
In the Bootstrap
protected function _initConstants()
{
$registry = Zend_Registry::getInstance();
$registry->constants = new Zend_Config( $this->getApplication()->getOption('constants') );
}
Then I can access these constants from any place in the application (model, controller, etc.)
Zend_Registry::getInstance()->constants->site_key
in
application/configs/application.ini
myvar = myvalue
after get them like :
$myvar = $application->getOption('myvar');
Have you tried Zend_Registry? It's used to store application-wide values, objects etc.
Store:
Zend_Registry::set('index', $value);
Retrieve:
$value = Zend_Registry::get('index');