2017-02-20 90 views
1

我想从数据库中删除一个项目并从表中删除它 实体产品 我想选择所有产品,并且在点击按钮xi后希望它更新名称并删除它从表 任何帮助? 我的树枝:更新我的数据库并丢弃表中的元素

<script> 

    $("document").ready(function() { 

     $(".btn-group-vertical").click(function() { 

      $.ajax({ 
       type:'get', 
       url:'http://localhost/symfony/nouveau%20dossier/web/app_dev.php/'+$(this).val(), 
       beforeSend: function() { 

       }, 
       success: function(data){ 
        var x = $("produit").val(data.approuver); 
        console.log(x); 
        $("tt").find('td').fadeOut(1000,function(){ 
         $("tt").remove(); 
        }); 

       } 



      }); 



     }); 





    }); 


</script> 
{% endblock script %} 
{% block body %} 
<section class="content"> 
<div class="row"> 
    <div class="col-xs-12"> 
     <div class="box"> 
      <div class="box-header"> 
       <h3 class="box-title">Produit en attente</h3> 
      </div> 
      <!-- /.box-header --> 
      <div class="box-body"> 
       <table id="example2" class="table table-bordered table-hover"> 
        <thead> 
        <tr> 
         <th>Produit de</th> 
         <th>Libelle Produit</th> 
         <th>Quantite stock</th> 
         <th>etat</th> 
        </tr> 
        </thead> 

        <tbody> 
        {% for product in products %} 
         <tr class="tt"> 
          <td align="center">{{ product.seller }}</td> 
          <td align="center">{{ product.libelle }}</td> 
          <td align="center">{{ product.quantiteStock }}</td> 
          <td><button 
            type="button" 

            class="btn btn-group-vertical btn-danger btn-xs" 
            id=1>Decliner</button> 



          <button type="button" 

            class="btn btn-group-vertical btn-sucess btn-xs" 
            id=2>Approuver</button> 
          </td> 
         </tr> 
        {% endfor %} 
        <tfoot> 
        <tr> 
         <th>Produit de</th> 
         <th>Libelle Produit</th> 
         <th>Quantite stock</th> 
         <th>etat</th> 
        </tr> 
        </tfoot> 
       </table> 
      </div> 
      <!-- /.box-body --> 
     </div> 
     <!-- /.box --> 
    </div> 
</div> 
<!-- ./wrapper --> 

我的控制器:

public function approuverAction($id) 
    { 

    $em = $this->getDoctrine()->getEntityManager(); 
    $produit = $em->getRepository('ProductBundle:Product') 
     ->findOneBy(array('id'=>$id)); 

    $produit->setApprouver('Approuver'); 


    $respones = new JsonResponse(); 
    return $em->merge($produit); 
    $em->flush(); 
    } 

任何帮助,请

+0

为什么要重命名要删除的内容? – goto

回答

0

我想从数据库中删除一个项目,从表实体删除 产品

删除产品:

$em->remove($produit); 
$em->flush();