如何从Symfony2 config.yml中读取配置设置? [英] How do I read configuration settings from Symfony2 config.yml?

查看:745
本文介绍了如何从Symfony2 config.yml中读取配置设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的config.yml文件添加了一个设置:

  app.config:
contact_email :somebody@gmail.com
...

对我来说,不知道如何读取它变成一个变量。我在我的控制器中尝试过这样的操作:

  $ recipient = 
$ this-> container-> ; getParameter('contact_email');

但我得到一个错误:


参数contact_email必须定义


,我也在Symfony2重新加载的网站文档,无处不在,但我找不到如何做这个。



现在可能只是太累了。 c>

code> app.config ,在参数条目中定义它:

 参数:
contact_email:somebody@gmail.com

你应该发现你在你的控制器中的呼叫现在工作。


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:

The parameter "contact_email" must be defined.

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?

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆