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条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了