我有几个常量,我需要为我的应用程序定义,例如SITE_KEY,它将包含盐密码的随机密钥.
我不知道我应该在哪里定义这些.我想把它们放在public / index.PHP中,但这似乎有点凌乱.有没有一个特定的地方,他们应该去,根据Zend或什么?
谢谢
编辑
我试图这样做:
在我的application.ini我有这个:
siteglobal.sitekey =“test”
并在我的bootstrap.PHP文件中:
protected function _initGlobals()
{
$config = $this->getoptions();
define('SITE_KEY',$config['siteglobal']['sitekey']);
}
不过,这是不行的,当我试图回应SITE_KEY在我的控制器像这样:
回应SITE_KEY;
它没有显示任何东西.有任何想法吗?
在我的申请中,我结合了Haim和Yeroon的方法.我正在将应用程序常量存储在我的application.ini中,然后在Bootstrap中解析它们并将其放入Zend_Registry中.
所以,在application.ini中
constants.site_key = my_site_key
在Bootstrap
protected function _initConstants()
{
$registry = Zend_Registry::getInstance();
$registry->constants = new Zend_Config( $this->getApplication()->getoption('constants') );
}
然后我可以从应用程序(模型,控制器等)中的任何位置访问这些常量
Zend_Registry::getInstance()->constants->site_key