Question

I have a problem with my Symfony2.2 beta routes. (symfony-2-2-0-beta-1)

I use annoations routes like this:

@Route("/form/{id}", defaults={"id"=0}, requirements={"id"="\d+"});

And the error is:

An exception has been thrown during the rendering of a template ("Parameter "id" for route "[...]_form" must match "\d+" ("" given).") in [...]:form.html.twig at line 1.

The line 1 is:

{{ path("[...]_form") }}

I think the route is correct, because I define "id=0" as default. And in Symfony2.1 the same code works.

Was it helpful?

Solution

Have you tried setting the default in your action and taking it out of the annotation?

/**
 * @Route("/form/{id}", name="my_form", requirements={"id"="\d+"});
 */
public function myFunction($id = 0){
...

I believe this is one of the changes in Symfony 2.2 although I haven't tried it yet. http://symfony.com/blog/new-in-symfony-2-2-small-things-matter#defining-default-values-when-using-the-route-annotation

OTHER TIPS

You can try

    requirements:
    id: \S|\d+
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top