php - Symfony2 "Parameter ""for route ""must match "[^/]++"(""given) to generate a corresponding URL."

标签 php symfony url routes yaml

我有这个路线文件:

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 编写规则的问题,但我不知道如何修复此错误。我尝试过在我的 route 添加这一行:

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

或者像这样的要求:

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

但是不匹配。有人可以帮忙吗?

谢谢...

最佳答案

就像@Coussinsky 所说,您的字段“nom”的一些在您的数据库中是空的。

如果需要,您可以将此参数设为null,或者只是更改数据库中的空值。

关于php - Symfony2 "Parameter ""for route ""must match "[^/]++"(""given) to generate a corresponding URL.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28454772/

相关文章:

PHP mkdir( $recursive = true ) 跳过最后一个目录

php - 如何在 WordPress 中获取评论永久链接(使用 HTML anchor )?

php - Symfony2 : Doctrine does not load related entities in many-to-many relation

Java - 通过浏览器/URL 连接到 ServerSocket

Java JSoup : Modifying URL

php - 从 mysql 数据库中提取 URL 并设置为单个单词可点击链接

php - 类 App\Http\Controllers\AuthController 不存在 Laravel 5.2

php - 数据库更新时jquery更新页面

php - 无法在 Monolog 的 yaml 配置中为 native_mailer 设置 content_type?

php 查询 - 按日期过滤