简体   繁体   English

Codeigniter中的购物车无法正常工作

[英]Shopping cart in codeigniter not working properly

I am new to codeigniter framework I have created one cart using codeigniter library. 我是Codeigniter框架的新手,我已经使用Codeigniter库创建了一个购物车。 The problem of the cart is that when I want to remove the product from the cart then the product is not removing immediately from the cart rather i have to press F5 ie refresh the whole page then it appears correctly does there is any problem with the codeigniter or I am doing any wrong logic. 购物车的问题是,当我想从购物车中取出产品时,该产品不是立即从购物车中取出,而是我必须按F5键,即刷新整个页面,然后看来正确,那么代码点火器是否存在任何问题或我做任何错误的逻辑。

Following is the cart controller to remove the product from my cart 以下是从我的购物车中删除产品的购物车控制器

  function remove($rowid) {
    $data = array(
        'rowid' => $rowid,
        'qty' => 0
    );
    $this->cart->update($data);
    $this->load->view('cart');  
}

Following is the link to remove the product from the cart 以下是从购物车中删除产品的链接

 <a href="<?php echo base_url(); ?>cart/remove/<?php echo trim($items['rowid']); ?>">remove</a>

try this. 尝试这个。 use redirect to redirect page 使用重定向来重定向页面

function remove($rowid) {
    $data = array(
        'rowid' => $rowid,
        'qty' => 0
    );
  $this->cart->update($data);

    redirect(site_url('cart'), 'refresh');
}

Try this may works for you: you should redirect after update your database do not us $this->load 试试看,这可能对您有用:更新数据库后,您应该重定向,不要使用$ this-> load

your controller 您的控制器

class Cart extends CI_Controller
  function index(){
    $this->load->view('cart');  
  }
  function remove($rowid) {
    $data = array(
        'rowid' => $rowid,
        'qty' => 0
    );
    $this->cart->update($data);
    redirect('cart', 'refresh');
  }
}

your view: 您的看法:

<a href="<?php echo base_url(); ?>cart/remove/<?php echo trim($items['rowid']); ?>">remove</a>

you are not sending $data to your view. 您没有将$ data发送到视图。 Try to change in your controller 尝试更改您的控制器

 $this->load->view('cart',$data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM