0
votes

i'm working on symfony2 project, when opening index page I got route error like this :

An exception has been thrown during the rendering of a template ("Parameter "id" for route "gmjob_examination_front_view" must match "[^/]" ("4719" given).") in GmjobExaminationBundle:Front:list.html.twig at line 25.

This is my list.html.twig line 25 :

<a href="{{ path(view.mainRouteName, view.mainRouteParams) }}"><h2>{{ view.title }}</h2></a>

This is the route annotation:

 * @Route("/detail-concours/{id}/{slug}", requirements = {"id" = "[^/]"})

here are the two methods of examination class Entity:

public function getMainRouteName()
{
    return 'gmjob_examination_front_view';
}

public function getMainRouteParams()
{
    return array(
        'id'   => $this->id,
        'slug' => $this->slug
    );
}

I appreciate your help. Thank you before.

1

1 Answers

0
votes

You have set requirements for id parameter to be [^/], which essentially means: Id must match any single character except /.

You probably meant, as @Cherry said [^/]+. If it is so, you can remove requirements part all together because exactly that is the default parameter regex in Symfony Router.

So just make it:

* @Route("/detail-concours/{id}/{slug}")

Tip: If your id is always an integer, you probably want to make it:

* @Route("/detail-concours/{id}/{slug}", requirements = {"id" = "\d+"})