1

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.

Luke
  • 3,333
  • 2
  • 28
  • 44
PatrickB
  • 3,225
  • 5
  • 31
  • 55

2 Answers2

1

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

Mark
  • 1,754
  • 1
  • 12
  • 14
-1

You can try

    requirements:
    id: \S|\d+
nvvetal
  • 1,756
  • 1
  • 17
  • 19
  • 1
    This is YAML while the question is about PHP annotation, and there is already a valid answer. – A.L May 07 '15 at 18:45