0

Controller , I can't found how using POST method without form in this part

public function validerReservationAction(Request $request,$id) {    
        $em = $this->getDoctrine()->getEntityManager();
        $reserv = $em->getRepository('LacarteRestBundle:Reservation')->findOneBy(array('id' => $id));

      if ($this->getRequest()->getMethod() == "POST") {
          // $reserv = $_POST['OkResto'];     
            $reserv->setOkResto(1);
            $em->persist($reserv);
            $em->flush();
    }
            return $this->FindAllRsvAction();
        }

routing yml

  lacarte_rest_validerRsv:
            path:     /tableRsv/{id}
            defaults: { _controller: LacarteRestBundle:Rsv:validerReservation } 

This is the view

<a href="{{ path('lacarte_rest_validerRsv', { 'id': reservation.id })}}" title="Valider"><i class="splashy-check"></i></a>
Marou
  • 1
  • 4
  • $request->request->get('OkResto'); http://stackoverflow.com/questions/9784930/how-to-get-the-request-parameters-in-symfony2/9788435#9788435 – Cerad Nov 20 '15 at 15:04
  • I try it before and doesn't work for me: – Marou Nov 20 '15 at 15:10
  • I try this; if ($this->getRequest()->getMethod() == "POST") { $request->request->get('OkResto'); $reserv->setOkResto(1); $em->persist($reserv); $em->flush(); } – Marou Nov 20 '15 at 15:11
  • Consider updating your question with your actual code. If you are indeed posting a OkResto then the code shown in the comment will work. Might use F12 in the browser or perhaps the profile bar to determine what exactly is being posted. – Cerad Nov 20 '15 at 15:12
  • By the way, the twig template strongly suggests you are issuing a GET request and not a post. Maybe show your form. – Cerad Nov 20 '15 at 15:15
  • I change my path like that but i still some mistake in controller, how coud i setOkResto(1) manually with post method: lacarte_rest_validerRsv: path: /tableRsv defaults: { _controller: LacarteRestBundle:Rsv:validerReservation } – Marou Nov 20 '15 at 15:29
  • Start by reading your own comments. Can you make any sense out of them? Comments are not really good for multiple lines of code. Hit the edit button under your question and update it with your actual code so we can read it. – Cerad Nov 20 '15 at 15:32
  • Furthermore, I am beginning to suspect that you want an html href to generate a POST request? Not going to happen. You need an html form or perhaps some java script. – Cerad Nov 20 '15 at 15:33
  • I'm using twig in href, it try it before to call path. i need to know how could i setOkResto(1) with post method – Marou Nov 20 '15 at 15:40
  • You need to use a form to generate a POST request. Either use the Symfony form component (http://symfony.com/doc/current/book/forms.html) or change your template to generate a html form element. If you don't understand this then you need to step back and find a introduction to html tutorial. You won't get very far without at least a basic understanding of html. This might also help: http://symfony.com/doc/current/book/http_fundamentals.html – Cerad Nov 20 '15 at 15:48

1 Answers1

0

use the getter function of the request object, it will retrieve the correct value, doesnt matter if post or get

  if ($this->getRequest()->getMethod() == "POST") {
        $reserv->setOkResto($request->get('OkResto'));
        $em->persist($reserv);
        $em->flush();
}
john Smith
  • 17,409
  • 11
  • 76
  • 117