symfonyconfiguration

How do I read configuration settings from Symfony2 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:

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?


Solution

  • 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.