[英]Symfony2 Routing annotation Error
i'm working on symfony2 project, when opening index page I got route error like this : 我正在symfony2项目上,打开索引页时出现如下路线错误:
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. 呈现模板时,在GmjobExaminationBundle:Front:list.html.twig中的模板渲染过程中引发了异常(路由“ gmjob_examination_front_view”的“参数” id”必须与“ [^ /]”(给出的“ 4719”)匹配)。第25行。
This is my list.html.twig line 25 : 这是我的list.html.twig第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.
谢谢你
You have set requirements for id parameter to be [^/]
, which essentially means: Id must match any single character except /
. 您已将id参数的要求设置为
[^/]
,这实际上意味着:ID必须匹配/
以外的任何单个字符。
You probably meant, as @Cherry said [^/]+
. 正如@Cherry所说
[^/]+
,您可能是说。 If it is so, you can remove requirements
part all together because exactly that is the default parameter regex in Symfony Router. 如果是这样,则可以一起删除
requirements
部分,因为这正是Symfony Router中的默认参数regex。
So just make it: 所以只要做到:
* @Route("/detail-concours/{id}/{slug}")
Tip: If your id
is always an integer, you probably want to make it: 提示:如果您的
id
始终是整数,则可能要使用它:
* @Route("/detail-concours/{id}/{slug}", requirements = {"id" = "\d+"})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.