Zend 配置继承
我的 application.ini 中有这些值
[production]
; Database;
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "user1"
resources.db.params.password = "password1"
resources.db.params.dbname = "projects__01"
;Names
website.settings.websiteName = "My website 1"
website.settings.websiteUrl = "http://www.mydomain1.com"
website.settings.title = "mydomain.com - mydomain"
website.settings.titleSeperator = " - "
[staging : production]
; Database;
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "user2"
resources.db.params.password = "password2"
resources.db.params.dbname = "projects__02"
;Exceptions
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
;Title and url
website.settings.websiteName = "My website 2"
website.settings.websiteUrl = "http://www.mydomain2.com"
[development : staging]
;Database
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "user3"
resources.db.params.password = "password3"
resources.db.params.dbname = "projects__03"
;Title and url
website.settings.websiteName = "My website 3"
website.settings.websiteUrl = "http://www.mydomain3.com"
问题是所有数据库和异常值都正常工作,这意味着它们按照预期正确继承
但是我为 Title 和 url 设置的值没有正确继承,只有第一个定义的值被使用。
这是为什么呢?这是设计使然吗?是否仅继承预定义/标准环境值(例如数据库和异常)?
或者我在某个地方犯了错误?
I have these values in my application.ini
[production]
; Database;
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "user1"
resources.db.params.password = "password1"
resources.db.params.dbname = "projects__01"
;Names
website.settings.websiteName = "My website 1"
website.settings.websiteUrl = "http://www.mydomain1.com"
website.settings.title = "mydomain.com - mydomain"
website.settings.titleSeperator = " - "
[staging : production]
; Database;
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "user2"
resources.db.params.password = "password2"
resources.db.params.dbname = "projects__02"
;Exceptions
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
;Title and url
website.settings.websiteName = "My website 2"
website.settings.websiteUrl = "http://www.mydomain2.com"
[development : staging]
;Database
resources.db.adapter = "pdo_mysql"
resources.db.params.host = "localhost"
resources.db.params.username = "user3"
resources.db.params.password = "password3"
resources.db.params.dbname = "projects__03"
;Title and url
website.settings.websiteName = "My website 3"
website.settings.websiteUrl = "http://www.mydomain3.com"
The problem is all database and exception values work properly, meaning that they are inheriting properly as they are supposed to
But the values I have set for Title and url do not inherit properly, only the first defined ones are used.
Why is this? is this by design? are only predefined/standard environment values such as database and exceptions are inherited?
Or am I making a mistake somewhere?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,从您的评论来看,您似乎正在引导程序中创建一个新的 Zend_Config 对象,并将其放入注册表中,而这并没有返回您所期望的结果。如果是这种情况,我猜测您省略了配置对象上的第二个参数,因此您有这样的内容:
但您应该拥有的更像是这样的:
第二个参数告诉它配置文件的哪个部分使用,否则它将始终获得相同的值。
然而,您实际上不需要重新解析配置文件,因为 Zend Application 已经完成了这项工作。相反,您可以从引导类访问选项并使用它们来创建对象(或者仅将选项存储在现有的数组格式中):
这应该按您的预期工作。
如果我的猜测是错误的,请您编辑您的问题以包含引导程序的相关部分,其中创建配置对象并将其存储在注册表中。
Okay, from your comment it sounds like you are creating a new Zend_Config object in the bootstrap, putting this in the registry, and it's this that's not returning what you'd expect. If this is the case I'm guessing that you've omitted the second parameter on the config object, so you have something like this:
but what you should have is more like this:
the second param tells it what section of the config file to use, without that it will always get the same value.
However, you don't actually need to re-parse the config file since Zend Application has done this already. Instead you can access the options from the bootstrap class and use these to create an object (or just store the options in their existing array format):
and this should work as you expect.
If my guess was wrong, please can you edit your question to include the relevant part of your bootstrap where the config object is created and stored in the registry.