Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: accessing variables defined in config.yml and config_*.yml

Tags:

php

symfony

Let's say I have a simple traditional contact form on my site and I would like it to use the subject "Test: (subject_field value)" in dev environment and "(subject_field_value)" in prod environment when sending e-mail. Is there a way to define a variable called "subject_prefix" in config_dev.yml and config_prod.yml and then just use something like $this->get('config')->get('subject_prefix')? I would expect that call to return "Test: (subject_field value)" in dev environment and "(subject_field_value)" in prod environment.

like image 795
Ohas Avatar asked Dec 17 '11 11:12

Ohas


1 Answers

The best to do is :

In the config.yml

parameters:
    url: domain.com

In the controller :

$value = $this->container->getParameter('url');

Hope it helps.

In Symfony 2.7+:

$value = $this->getParameter('url');
like image 166
Mirza Selimovic Avatar answered Sep 19 '22 07:09

Mirza Selimovic