Zend 中应用程序常量存储在哪里?
我需要为我的应用程序定义一些常量,例如 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 时,如下所示:
echo SITE_KEY;
它不显示任何内容。有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在我的应用程序中,我结合了 Haim 和 Yeroon 的方法。我将应用程序常量存储在
application.ini
中,然后在Bootstrap
中解析它们并将它们放入Zend_Registry
中。因此,在
application.ini
中的Bootstrap
然后我可以从应用程序中的任何位置(模型、控制器等)访问这些常量
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 theBootstrap
and putting them intoZend_Registry
.So, in the
application.ini
In the
Bootstrap
Then I can access these constants from any place in the application (model, controller, etc.)
您是否尝试过Zend_Registry?它用于存储应用程序范围的值、对象等。
存储:
检索:
Have you tried Zend_Registry? It's used to store application-wide values, objects etc.
Store:
Retrieve:
在
后获取它们如下:
阅读更多。 ...
in
after get them like :
read more ....