如何从 Symfony2 config.yml 读取配置设置? [英] How do I read configuration settings from Symfony2 config.yml?
问题描述
我已经在我的 config.yml 文件中添加了一个设置:
I have added a setting to my config.yml file as such:
app.config:
contact_email: somebody@gmail.com
...
对于我的一生,我不知道如何将其读入变量.我在我的一个控制器中尝试了这样的事情:
For the life of me, I can't figure out how to read it into a variable. I tried something like this in one of my controllers:
$recipient =
$this->container->getParameter('contact_email');
但我收到一条错误消息:
But I get an error saying:
参数contact_email"必须是定义.
The parameter "contact_email" must be defined.
我已经清除了我的缓存,我还查看了 Symfony2 重新加载站点文档的所有地方,但我不知道如何执行此操作.
I've cleared my cache, I also looked everywhere on the Symfony2 reloaded site documentation, but I can't find out how to do this.
现在可能太累了,无法弄清楚这一点.有人可以帮忙吗?
Probably just too tired to figure this out now. Can anyone help with this?
推荐答案
与其在 app.config
中定义 contact_email
,不如在 parameters
中定义它代码>条目:
Rather than defining contact_email
within app.config
, define it in a parameters
entry:
parameters:
contact_email: somebody@gmail.com
您应该会发现您在控制器中进行的调用现在可以正常工作了.
You should find the call you are making within your controller now works.
这篇关于如何从 Symfony2 config.yml 读取配置设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!