Codeigniter购物车无法添加商品

Alv*_*ack 2 php html5 shopping-cart codeigniter

所以我正在尝试使用购物车创建一个应用程序,当我尝试添加该项目时,它无法正常工作.顺便说一句,我已经有一个工作车应用程序,这就是为什么我想知道为什么它不工作.我几乎从工作中复制了所有东西.这是代码

推车控制器

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Cart extends CI_Controller {

public function __construct()
{
    parent::__construct();
    $this->load->library('cart');
}

public function add_to_cart(){

    $id = $this->uri->segment(3);
    if($this->cart->contents()){
        foreach ($this->cart->contents() as $item){
            if ($item['id']==$id){
                $data = array('rowid'=>$item['rowid'],
                    'qty'=>++$item['qty']);
                $process = $this->cart->update($data);
            }
            else{
                $data = array(
                    'id'=>$id,
                    'qty'=>1,                       
                    'name' => $this->get_data->get_value('product_name','products','product_id', $id),
                    'price' => $this->get_data->get_value('product_price','products','product_id', $id)
                    );
                $process = $this->cart->insert($data);
            }
        }
    }
    else{
        $data = array('id'=>$id,
                    'qty' =>1,
                    'name' => $this->get_data->get_value('product_name','products','product_id', $id),
                    'price' => $this->get_data->get_value('product_price','products','product_id', $id),
                    );
                    $process = $this->cart->insert($data);
    }


    if($process){
        $this->session->set_flashdata('success', 'Successful');
        redirect('products');
    }
    else{
        $this->session->set_flashdata('failed', 'Failed');
        redirect('products');
        //var_dump($process);
    }
}
Run Code Online (Sandbox Code Playgroud)

这是按钮

<div class="button pull-right" style="margin-top: 10px;"><a href="<?php echo base_url().'cart/add_to_cart/'.$row->product_id;?>"><span class="glyphicon glyphicon-shopping-cart"></span>Add to Cart</a></div>
Run Code Online (Sandbox Code Playgroud)

我真的看不出问题,我正在使用会话数据库,sess_us_database已经是TRUE.我尝试使用var_dump($process),它是假的,我试过var_dump($data),数据似乎很好,但插入部分不起作用.伙计们好吗?对我来说这将是一个很大的帮助,谢谢.

Raj*_*har 10

CI默认购物车仅允许alpha-numeric, dashes, underscores, colons or periods在产品名称中,如果产品价格0也是如此,它也不会将产品添加到购物车.

请先检查一下.