访问 Zend_Application_Bootstrap_Bootstrap 的 getOptions()
我使用默认的 Zend_Application
设计模式,该模式会在应用程序引导程序中自动加载 zend config ini 文件,并且我需要跨多个模型和控制器加载 ini 文件的变量。
现在,我通过将配置对象设置为 Zend_Registry
的键来解决这个问题:
protected function _initConfig()
{
$config = new Zend_Config($this->getOptions());
Zend_Registry::set('config', $config);
}
一般来说,我不喜欢使用 Zend_Registry
,因为它不提供代码在我的 IDE 中自动完成,并且很难跟踪注册表命名空间中的内容。
还有另一种方法可以访问 Zend_Application 的配置 ini 吗?
I'm using the default Zend_Application
design pattern which loads a zend config ini file automatically in the application bootstrap and I need to ini file's variables across many models and controllers.
Right now, I'm solving it by settings the config object as a key into Zend_Registry
:
protected function _initConfig()
{
$config = new Zend_Config($this->getOptions());
Zend_Registry::set('config', $config);
}
Generally, I don't like using Zend_Registry
, as it doesn't offer code auto complete in my IDE, and it's hard to keep track on what I have in the registry namespace.
Is there another way to access the Zend_Application's config ini?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在控制器中,您应该能够执行以下操作:
访问配置。对于模型,您确实应该传递您需要的选项。否则你唯一的选择就是注册表。
In a controller you should be able to do:
to access the config. For models you really should be passing in the options you need. Otherwise your only choice is really the registry.
您始终可以根据需要自己使用
Wich 初始化它,这几乎就是引导程序为您所做的事情。然后你就会在 $options 上自动完成。但每次需要时都必须对其进行初始化。
我认为修改代码以适应自动完成功能并不是最好的主意。但这是个人的。
如果我没有弄错 Zend Studio 8/9(也许是 7),即使对于
Zend_Registry::get()
返回的对象,您也确实具有自动完成功能。You could always initialise it as needed yourself with
Wich is pretty much what the bootstrap does for you. Then you would have autocomplete on $options. But you would have to initialise it everytime you need it.
I think modifying your code to suit autocomplete is not the greatest idea ever. But this is personnal.
If I am not mistaken with Zend Studio 8/9 (maybe 7) you DO have autocomplete even for objects returned by
Zend_Registry::get()
.