简体   繁体   English

Symfony2“参数”“用于路由”“必须匹配”[^ /] ++“(”“给定)以生成相应的URL。”

[英]Symfony2 “Parameter ”“ for route ”“ must match ”[^/]++“ (”“ given) to generate a corresponding URL.”

I have this routes file: 我有这个路线文件:

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

Now when I want to proceed to the indexRechercheZones route, an error occured : 现在,当我想继续使用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. 在渲染模板期间抛出异常(“参数”nom“for route”modifierZones“必须匹配”[^ /] ++“(”“给定)以生成相应的URL。”)在MySpaceGestion中... sBundle:...:第71行的indexZonesTechniques.html.twig。

In my twig line 71, I have this code : 在我的树枝线71中,我有这个代码

<a href="{{ path('modifierZones', {'nom': zonetechnique.nom}) }}"><button class="btn btn-warning btn-xs">Modifier</button></a>

I think that is a regex problem, a problem with the url writing rule for symfony, but I don't how I can fix this error. 我认为这是一个正则表达式问题,symfony的url编写规则存在问题,但我不知道如何修复此错误。 I have tried some thing like adding this line in my route: 我尝试过在我的路线中添加这一行的一些事情:

indexRechercheZones:
    path:     /gestionzonestechniques/
    defaults: { _controller: MySpaceGestionEquipementsTechniquesBundle:GestionZonesTechniques:indexZonesTechnique }
    requirements:
        nom:    \d+ 
    methods: GET

or like this at the requirements: 或者像这样要求:

requirements:
    nom:    '[a-zA-Z0-9-_\/-\s.^]+'

But it does not match. 但它不匹配。 Someone could help? 有人可以帮忙吗?

Thank you... 谢谢...

Like @Coussinsky said, some values for your field "nom" are empty on your database. 就像@Coussinsky所说,你的field “nom”的某些values在你的数据库中是空的。

You could make this parameter to null if you want, or just change the empty values on your database. 如果需要,可以将此参数设置null ,或者只更改数据库中的空值。

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

相关问题 Symfony2 允许空路由参数“必须匹配 ^/ ++(给定)以生成相应的 url” - Symfony2 allow empty route parameter “must match ^/ ++ ( given) to generate a corresponding url” Symfony generateUrl 问题 .... 必须匹配 &quot;[^/]++&quot; (&quot;my string with special chars&quot; given) 以生成相应的 URL。 - Symfony generatUrl problem .... must match "[^/]++" ("my string with special chars" given) to generate a corresponding URL." 路径“”的参数“”必须与“ [^ /] ++”(给出的“”)匹配,以生成相应的URL - Parameter “” for route “” must match “[^/]++” (“” given) to generate a corresponding URL Symfony2路由错误(参数 <x> 路线 <r> 必须匹配 <pattern> ) - Symfony2 routing error (parameter <x> for route <r> must match <pattern>) symfony2:使用表单更改URL路由参数 - symfony2: change url route parameter with a form Symfony2注释无法为命名路由生成URL - Symfony2 annotation Unable to generate a URL for the named route 如何在树枝模板中从symfony2路由名称生成URL? - How to generate a url from symfony2 route name in a twig template? symfony2 GET参数覆盖路由参数 - symfony2 GET parameter overrides route parameter 动作在Symfony2中是否必须具有路由? - Does Action must have a Route in Symfony2? 在 Symfony2 中生成具有特定方案的绝对 URL - Generate absolute URL with specific scheme in Symfony2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM