1

我使用 Symfony2,我想在表格中显示信息列表,但它产生了以下异常:

在 AffaireBundle:Affaires:affaires.html 中的模板渲染过程中引发了异常(“路由“affaire_voir_affaire”的“参数“id”必须匹配“\d+”(“”给定)以生成相应的 URL。”)。树枝在第 27 行。

thats is Routing.yml:

affaire_liste_affaires:
    pattern:  affaires/{page}
    defaults: { _controller: AffaireBundle:Affaires:lister, page: 1 } 
    requirements:
        page:  \d*
affaire_voir_affaire:
    pattern:  /{id}
    defaults: { _controller: AffaireBundle:Affaires:voir }
    requirements:
        id:  \d+
affaire_afficherformulaire_affaire:
    pattern:  ajouter
    defaults: { _controller: AffaireBundle:Affaires:afficherFormulaire }   
affaire_ajouterPC_affaire:
    pattern:  ajouterPompe_Chaleur
    defaults: { _controller: AffaireBundle:Affaires:ajouterPC }   
affaire_modifier_affaire:
    pattern:  modifier/{id}
    defaults: { _controller: AffaireBundle:Affaires:modifier } 
    requirements:
        id:  \d+
affaire_supprimer_affaire:
    pattern: supprimer/{id}
    defaults: { _controller: AffaireBundle:Affaires:supprimer }
    requirements:
        id:  \d+

affaire_rechercher_affaire:
    pattern: rechercher
    defaults: { _controller: AffaireBundle:Affaires:rechercher }
    requirements:
        _method:  POST
4

1 回答 1

1

The exception message is quite obvious in my opinion. You require the id parameter of your route to match the regular expression \d+ (wich is a number) and your call differs from that. You probably pass the wrong parameter to the twig path() method. Also be aware that for that rout only POST is allowed as an HTTP-Method so be sure to check for that aswell.

于 2013-06-05T10:17:32.987 回答