dongnai2804 2017-09-21 13:22
浏览 83
已采纳

如何使用购物车会话Codeigniter删除项目

I am currently developing an ecommerce system and I am already in the part of ordering module. I am using the shopping cart of Codeigniter and it is my first to do it.

Done in a part of add to cart but having problem in remove single item in cart session. When I clicked the Remove, everything in my cart will be remove.

Question: How can I remove a single item in my cart?

View

<?php foreach ($this->cart->contents() as $items): ?>
        <tr>
              <td><?= $items['name']?></td>
              <td><?= $items['qty']?></td>
              <td style="text-align:center"><span>&#8369;<?= $this->cart->format_number($items['price'])?></span></td>
              <td style="text-align:center"><span>&#8369;<?= $items['subtotal']?></span></td>
              <td><a href="<?= base_url().'user/remove_cart'?>"><button class="btn btn-primary btn-sm"><i class="fa fa-times" aria-hidden="true"><?= $this->cart->remove($items['rowid'])?>REMOVE</i></button></a></td> 
        </tr>
<?php endforeach; ?>

Controller

public function remove_cart($rowid)
    {
        $removed_cart = array(
            'rowid'         => $rowid,
            'qty'           => 0
        );
         $this->cart->update($removed_cart);
    }
}
  • 写回答

4条回答 默认 最新

  • duanpuluan0480 2017-09-21 14:13
    关注

    This code removes the cart items

    <td><a href="<?= base_url().'user/remove_cart'?>"><button class="btn btn-primary btn-sm"><i class="fa fa-times" aria-hidden="true"><?= $this->cart->remove($items['rowid'])?>REMOVE</i></button></a></td>
    

    this part

    <?= $this->cart->remove($items['rowid'])?>
    

    Here it gets removed

    remove the code and you can try like this.

    <td>
          <a href="<?= base_url().'user/remove_cart/'.$items['rowid']; ?>">
              <button class="btn btn-primary btn-sm"><i class="fa fa-times" aria-hidden="true">REMOVE</i></button>
          </a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料