Codeigniter:购物车删除不工作

时间:2017-11-15 22:31:24

标签: php codeigniter

我正在尝试从购物车中删除该项目,这是我的代码:

 function remove($rowid) {
                 if ($rowid==="all"){
                    $this->cart->destroy();
                }
                else{
                    $data = array(
                    'rowid' => $rowid,
                    'qty' => 0
                    );
                    $this->cart->update($data); 
                 }
            redirect(base_url()."cart/viewcart");
         }

在我的购物车视图中,这是我的代码

echo form_open('cart/update_cart');
$grand_total = 0;
$i = 1;

foreach ($cart as $item):
echo form_hidden('cart[' . $item['id'] . '][id]', $item['id']);
echo form_hidden('cart[' . $item['id'] . '][rowid]', $item['rowid']);
echo form_hidden('cart[' . $item['id'] . '][name]', $item['name']);
echo form_hidden('cart[' . $item['id'] . '][price]', $item['price']);
echo form_hidden('cart[' . $item['id'] . '][qty]', $item['qty']);
?>
<tr>
<td>
<?php echo $i++; ?>
</td>
<td>
<?php echo $item['name']; ?>
</td>
<td>
 <?php echo number_format($item['price'], 2); ?>
</td>
<td>
<?php

 $numberfield = array( 'type' => 'number', 'class' => 'form-control qty ' );
 echo form_input('cart[' . $item['id'] . '][qty]', $item['qty'], 'maxlength="3" size="1" style="text-align: right"',$numberfield); ?>
</td>
<?php $grand_total = $grand_total + $item['subtotal']; ?>
<td>
AED <?php echo number_format($item['subtotal'], 2) ?>
</td>
<td>

<?php
// cancle image.
$url = base_url().'assets/img/cross.png';
$path ="<img src='$url' width='20' height='20'>";
echo anchor(base_url().'cart/remove/' . $item['rowid'], $path); ?>
</td>
<?php endforeach; ?>

问题是购物车商品没有从购物车中删除

我试图使用下面的代码销毁购物车,但它不起作用

   $this->cart->destroy();

0 个答案:

没有答案