问题描述
我想做的很简单:将数据存储在一个我以后想阅读的自定义配置文件中。
What I want to do is quite simple: store data in a custom config file that I want to read later on.
我创建了文件<$ c $我在全局 config
目录中放置的c> something.yml 。
看起来像这样:
I created my file something.yml
that I put in the global config
directory.It looks like that:
prod:
test: ok
dev:
test: ko
all:
foo: bar
john: doe
然后我复制了config_handlers.yml并将其放在config目录中,并在文件顶部添加了以下内容:
Then I copied the config_handlers.yml and also put it in the config directory and added the following at the top of the file:
config/something.yml:
class: sfDefineEnvironmentConfigHandler
param:
prefix: something_
但是如果我呼叫 sfConfig :: get( something_foo);
我一直在得到 NULL
。
But if I'm calling sfConfig::get("something_foo");
I keep getting NULL
.
我做错了什么?
我只想读取值,因此无需创建自定义配置处理程序,对吧?
What did I do wrong?I just want to read values, so no need to create a custome config handler, right?
我已经在此处阅读文档:,即使我运行的是1.4(我认为从那以后也没有改变)。
I've read the doc here: http://www.symfony-project.org/book/1_2/19-Mastering-Symfony-s-Configuration-Files even though I'm running 1.4 (I don't think that changed since then).
编辑:当然,我可以使用 sfYaml :: load()
,但我想以更好的方式来做事情。
Of course I can use sfYaml::load()
but I'd like to do things in a better way.
推荐答案
不要修改index.php,这太脏了!
Do not modify the index.php this is dirty!
Juste添加了这个行到您的应用程序/frontend/config/frontendConfiguration.class.php
Juste add this line to your app/frontend/config/frontendConfiguration.class.php
require_once($this->getConfigCache()->checkConfig('config/something.yml'));
(使用您自己的应用程序名称进行修改)
(adapt with your own app name)
这篇关于如何在Symfony中创建自定义yaml配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!