2

How can I get values from config.yml or security.yml in the controller in Symfony2? I am not talking about the ones I define under "parameters" key (which one can easily get by $this->container->getParameter()), but those stored in upper levels.

For example, how can I get the security.firewalls.my_firewall.remember_me.key value?

2
  • There is nothing wrong with the approach if you need custom parameters, but I need the values which I specify for the framework anyway - like the remember_me.key. What's the point in duplicating this value in the config? Commented Jan 31, 2012 at 9:38
  • You're right, I should do it this way. Thanks for your input, post it as an answer and I will accept it (+rep) ;) Commented Feb 1, 2012 at 12:22

1 Answer 1

2

What's wrong with defining a value as a parameter and assigning it to a value in config.yml or security.yml? You can easily get it from a controller then.

For example, add a parameter to the parameters.ini file:

remember_me_key = some_key_here

And then use it in the security.yml file:

security.firewalls.my_firewall.remember_me.key: %remember_me_key%

And access it from a controller the way you already do.

Sign up to request clarification or add additional context in comments.

1 Comment

how do he access it from a controller "the way you already do"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.