user2455102
user2455102

Reputation: 11

Symfony 2.2 exception

I work with Symfony2 and I want to display a list of information in a table, but it has generated me the following exception:

An exception has been thrown during the rendering of a template ("Parameter "id" for route "affaire_voir_affaire" must match "\d+" ("" given) to generate a corresponding URL.") in AffaireBundle:Affaires:affaires.html.twig at line 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

Upvotes: 1

Views: 1726

Answers (1)

ferdynator
ferdynator

Reputation: 6410

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.

Upvotes: 1

Related Questions