2017-02-20 129 views
0

我正在尝试解决symfony项目中的问题。我希望用户从列中的下拉列表中选择一个值(完成),然后更新数据库中的新值。事情是,当我点击更新值时,它会得到旧值并且不会更新。这里是PHP代码从列下拉列表中Symfony更新

/** 
* @Route("/pedidoventa/edit/{id}", name="pventa_edit") 
*/ 
public function editpventaAction($id, Request $request) 
{ 
    $Pedido_Venta = $this->getDoctrine() 
     ->getRepository('AppBundle:Pedido_Venta') 
     ->find($id); 


    $Pedido_Venta->setEstado($Pedido_Venta->getEstado()); 


     //traer los datos 

     $estado = ($Pedido_Venta->getEstado()); 


     $em = $this->getDoctrine()->getManager(); 
     $Pedido_Venta = $em->getRepository('AppBundle:Pedido_Venta')->find($id); 

     $Pedido_Venta->setEstado($estado); 


     $em->flush(); 

     $this->addFlash(
      'notificacion', 
      'Estado Editado' 
     ); 

     return $this->redirectToRoute('pventa_list'); 
    } 

这里是HTML表格

{% extends 'base.html.twig' %} 

{% block body %} 
    <h2 class="page-header">Pedidos de Venta</h2> 
    <table class="table table-striped"> 
    <thead> 
    <tr> 
    <th>#</th> 
    <th>Fecha - Hora</th> 
    <th>Estado</th> 
    <th>Total</th> 
    </tr> 
    </thead> 
    <tbody> 
    {% for Pedido_Venta in pedidosventa %} 
    <tr> 
    <th scope="row">{{Pedido_Venta.id}}</th> 
    <td><a href="/pedidoventa/details/{{Pedido_Venta.id}}">{{Pedido_Venta.fecha}}</a></td> 
    <td><select> 
      <option selected="selected">{{Pedido_Venta.estado}}</option> 
      <option>Listo</option> 
      <option>Con Demora</option> 
     </select> 
    </td> 
    <td></td> 
    <td> 
    <a href="/pedidoventa/edit/{{Pedido_Venta.id}}" class="btn btn-info">Editar</a> 
    <a href="/pedidoventa/delete/{{Pedido_Venta.id}}" class="btn btn-danger">Eliminar</a> 
    </td> 
    </tr> 
    {% endfor %} 
    </tbody> 
    </table> 
    <a href="/pedidoventa/create" class="btn btn-primary">Nuevo Pedido de Venta</a> 
{% endblock %} 

任何帮助将是非常赞赏

+1

在你的控制器中,你为什么得到'Pedido_Venta'并且设置了两次'estado'值? – goto

回答

2

你只发送ID。看看你的HTML,没有任何<form>标签,它正在等待你的下拉列表中的参数。请创建表单来处理您的问题。