简体   繁体   English

Symfony2路由错误(参数 <x> 路线 <r> 必须匹配 <pattern> )

[英]Symfony2 routing error (parameter <x> for route <r> must match <pattern>)

I'm kind of new in Symfony2 Framework. 我在Symfony2 Framework中是新手。 This error take forever me to solved. 这个错误需要我永远解决。 I build my own project based from Jobeet tutorial. 我根据Jobeet教程构建自己的项目。 Now I've success till generate CRUD but when opening index page I got route error like this : 现在,在生成CRUD之前,我已经成功了,但是当打开索引页时,出现了这样的路由错误:

An exception has been thrown during the rendering of a template ("Parameter "id" for route "sifo_mst_periode_show" must match "[^/]++" ("" given) to generate a corresponding URL.") in SifoSchoolBundle:MstPeriode:index.html.twig at line 21. 在SifoSchoolBundle:MstPeriode中,在呈现模板的过程中引发了异常(路由“ sifo_mst_periode_show”的“参数“ id”必须与“ [^ /] ++”(给定的““”相匹配以生成相应的URL。):第21行的index.html.twig

This is my index.html.twig line 21 : 这是我的index.html.twig第21行:

<td><a href="{{ path('sifo_mst_periode_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>

This is the route : 这是路线:

sifo_mst_periode:
    pattern:  /
    defaults: { _controller: "SifoSchoolBundle:MstPeriode:index" }

sifo_mst_periode_show:
    pattern:  /{id}/show
    defaults: { _controller: "SifoSchoolBundle:MstPeriode:show" }

And this is the routing : 这是路由:

SifoSchoolBundle_sifo_mst_periode:
    resource: "@SifoSchoolBundle/Resources/config/routing/mstperiode.yml"
    prefix:   /periode

This Case has been solved. 此案已解决。 The problem is Primary Key (entity.id) had NULL Value which not show in Add Form. 问题是主键(entity.id)的NULL值未在添加表单中显示。 I make all Primary Key to auto and not handle by User Form. 我将所有主键设为自动,而不是由用户表单处理。

Thank You. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM