如何在Symfony2中使用没有表单的POST方法更新我的实体

时间:2015-11-20 14:59:59

标签: symfony

控制器,我在这部分中找不到如何使用没有表单的POST方法

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();
        }

路由yml

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

这是视图

<a href="{{ path('lacarte_rest_validerRsv', { 'id': reservation.id })}}" title="Valider"><i class="splashy-check"></i></a>

1 个答案:

答案 0 :(得分:0)

使用请求对象的getter函数,它将检索正确的值,无论是post还是get

  if ($this->getRequest()->getMethod() == "POST") {
        $reserv->setOkResto($request->get('OkResto'));
        $em->persist($reserv);
        $em->flush();
}