symfony - Send a post parameter with path -


i have list of demands, can remove some, have created path every demand that:

<a href="{{ path('etudiant_suprimer_demande',{'id':demande.id} )}} 

and have controller that:

class edudiantcontroller extends controller { //codes   public function suprimerdemandeaction($id){    //  echo $id;     $em = $this->getdoctrine()         ->getentitymanager();     $demande = $em->getrepository('acmeestmsitebundle:demande')         ->find($id);     if ($demande == null) {         throw $this->createnotfoundexception('demande[id='.$id.']inexistant');     }      if ($this->get('request')->getmethod() == 'post') {         $this->get('session')->getflashbag()->add('info', 'demande bien supprimée');         return $this->redirect( $this->generateurl('acme_estm_site_espace_etudiant'));      }      //return $this->render('sdzblogbundle:blog:supprimer.html.twig',array('demande' => $demande));     return new response(); } 

and routing is:

etudiant_suprimer_demande:     path:     /profile/espace/suprimerdemande/{id}     defaults: { _controller: acmeestmsitebundle:edudiant:suprimerdemande }     methods: post 

what want not show id of demands in url, means want action post method have error:

no route found "get /profile/espace/suprimerdemande/3": method not allowed (allow: post)

tl;dr

<form action="{{ path('etudiant_suprimer_demande',{'id': demande.id} )}}" method="post">   <button type="submit">delete</button> </form> 

explanation

the code have generates <a> link, when user clicks it, user agent sends get request server, error get.

in order create post request, need <form>.

to answer question regarding showing id in generated url, take @ this answer. you'll have change controller , routing.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -