-1

I have parameters in my yml :

// myparameter.yml
parameters:
    keekbootstrap4.color:
        blue:
            - color1
            - color2
        red:
            - color1
            - color2

In my Controller, I want to get the "blue" key :

/**
 * @Route("/keekbootstrap4-card-{color}.css", requirements={"color" = "%keekbootstrap4.color%"}, name="keekbootstrap4_card")
 */
public function indexAction()
{
    dump($this->container->getParameter('keekbootstrap4.color')[$color]);

But I have this error :

The container parameter "keekbootstrap4.color", used in the route configuration value "%keekbootstrap4.color%", must be a string or numeric, but it is of type array.

Can you help me ? It's possible to get array with key in Route url ? Thanks :)

4
  • 2
    Possible duplicate of PHP Array from YAML with Symfony Commented Nov 7, 2016 at 22:15
  • 2
    Why are you asking the same question twice? If you're not happy with the provided answer you can edit your original post at any time to further clarify what your issue is and what your expected anwer: stackoverflow.com/questions/40439734/… Commented Nov 7, 2016 at 22:16
  • I don't know if it will work but have you tried with requirements={"color": "%keekbootstrap4.color.blue.0%"|"%keekbootstrap4.color.blue.1%"} or requirements={"color": "%keekbootstrap4.color.blue.0%|%keekbootstrap4.color.blue.1%"} Commented Nov 7, 2016 at 22:45
  • symfony.com/doc/current/routing/… Commented Nov 8, 2016 at 6:50

1 Answer 1

1

I think you want to do it in this way:

/**
 * @Route("/keekbootstrap4-card-{color}.css", name="keekbootstrap4_card")
 */
public function indexAction($color)
{
    $colors = $this->getParameter('keekbootstrap4.color');

    if (!array_key_exists($color, $colors)) {
        throw $this->createNotFoundException();
    }

    dump($colors[$color]);
}
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.