【发布时间】:2014-04-28 15:49:32
【问题描述】:
我是 Symfony2 框架的新手。这个错误需要我永远解决。我根据 Jobeet 教程构建了自己的项目。现在我已经成功生成 CRUD,但是在打开索引页面时,我遇到了这样的路由错误:
在渲染模板期间引发了异常 (“路由“sifo_mst_periode_show”的参数“id”必须匹配“[^/]++” ("" given) 生成对应的 URL。") 在 SifoSchoolBundle:MstPeriode:index.html.twig 在第 21 行。
这是我的 index.html.twig 第 21 行:
<td><a href="{{ path('sifo_mst_periode_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
这是路线:
sifo_mst_periode:
pattern: /
defaults: { _controller: "SifoSchoolBundle:MstPeriode:index" }
sifo_mst_periode_show:
pattern: /{id}/show
defaults: { _controller: "SifoSchoolBundle:MstPeriode:show" }
这是路由:
SifoSchoolBundle_sifo_mst_periode:
resource: "@SifoSchoolBundle/Resources/config/routing/mstperiode.yml"
prefix: /periode
【问题讨论】:
-
确保
entity.id有一定的价值 -
如何初始化
entity?如果它在循环中,请确保检查entity.id是否为空或 null! -
@PCoder : Atually im using generate:crud command based Jobeet tutorial day 3 intelligentbee.com/blog/2013/08/09/… 它是自动生成的。
-
如何放置一个if条件来检查它是空还是空?
-
@PCoder :它的空值。似乎自动生成的表格没有将PK放入表格中。通常在 PHP 中,我会手动输入主键。如果这超出了主题,我很抱歉。但是我必须将所有PK更改为自动吗?因此它将在没有用户交互的情况下生成,而是将新字段作为用户界面的代码。