0

I want to get PHP Array from parameters.yml in Symfony, example :

parameters:
    keek.color:
        blue:
            - color1
            - color2
        red:
            - color3
            - color4

Is it possible?

2
  • Does Symfony disallow you from using the YAML extension? Commented Nov 5, 2016 at 15:11
  • How to set parameters in symfony Commented Nov 5, 2016 at 23:13

1 Answer 1

4

Yes, you can retrieve with the method getParameter on the container instance, as example:

$container->getParameter('keek.color');

In a controller with the shortcut:

    $this->getParameter('keek.color');

And will return an array:

array(2) {
  'blue' =>
  array(2) {
    [0] =>
    string(6) "color1"
    [1] =>
    string(6) "color2"
  }
  'red' =>
  array(2) {
    [0] =>
    string(6) "color3"
    [1] =>
    string(6) "color4"
  }
}
Sign up to request clarification or add additional context in comments.

Comments

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.