我有这个路线文件:
indexRechercheZones:
path: /gestionzonestechniques
defaults: { _controller: MySpaceGestionEquipementsTechniquesBundle:GestionZonesTechniques:indexZonesTechnique }
requirements:
methods: GET
modifierZones:
path: /gestionzonestechniques/modifier/{nom}
defaults: { _controller: MySpaceGestionEquipementsTechniquesBundle:GestionZonesTechniques:modifierZonesTechnique }
requirements:
methods: GET
modifierZones_process:
path: /gestionzonestechniques/modifier/process/{nom}
defaults: { _controller: MySpaceGestionEquipementsTechniquesBundle:GestionZonesTechniques:modifierZonesTechnique }
requirements:
methods: POST
现在,当我想继续使用indexRechercheZones路由时,发生错误:
An exception has been thrown during the rendering of a template
(“Parameter “nom” for route “modifierZones” must match “[^/]++” (“”
given) to generate a corresponding URL.”) in
MySpaceGestion…sBundle:…:indexZonesTechniques.html.twig
at line 71.
在我的树枝线71中,我有这个代码:
<a href="{{ path('modifierZones', {'nom': zonetechnique.nom}) }}"><button class="btn btn-warning btn-xs">Modifier</button></a>
我认为这是一个正则表达式问题,symfony的url编写规则存在问题,但我不知道如何修复此错误.我尝试过在我的路线中添加这一行的一些事情:
indexRechercheZones:
path: /gestionzonestechniques/
defaults: { _controller: MySpaceGestionEquipementsTechniquesBundle:GestionZonesTechniques:indexZonesTechnique }
requirements:
nom: \d+
methods: GET
或者像这样要求:
requirements:
nom: '[a-zA-Z0-9-_\/-\s.^]+'
但它不匹配.有人可以帮忙吗?
谢谢…
解决方法:
就像@Coussinsky所说,你的字段“nom”的某些值在你的数据库中是空的.
如果需要,可以将此参数设置为null,或者只更改数据库中的空值.