Codeigniter购物车插入失败

Codeigniter购物车插入失败,codeigniter,cart,Codeigniter,Cart,我知道这个问题已经被问到了,但我仍然找不到解决这个问题的办法 因此,我创建了一个数组并尝试将其插入购物车并显示内容,但结果是一个空数组: 控制器: public function add(){ $product = $this->emag_model->get_id($this->input->post('product_id')); $insert = array( 'id' =>$product->id,

我知道这个问题已经被问到了,但我仍然找不到解决这个问题的办法
因此,我创建了一个数组并尝试将其插入购物车并显示内容,但结果是一个空数组:
控制器:

 public function add(){


    $product = $this->emag_model->get_id($this->input->post('product_id'));

    $insert = array(

        'id' =>$product->id,
        'qty'     => 1,
        'price' =>$product->pret,
        'name'    =>  $product->nume,

    );
    $this->cart->insert($insert);

    redirect('emag/chart');
}
public function chart(){
    $this->renders();
      $this->load->view('emag/chart');
}
 <input type="hidden" name="product_id" value="<?php echo $laptop->id; ?> " />  
//$laptop->id retrieves the id of the curent product

 <table id="table_cart">


        <tbody>
        <?php foreach( $this->cart->contents() as $item): ?>
        <tr>
            <td>                   
                <?php echo  $item['name']; ?>
            </td>
            <td><?php echo $item['qty']; ?></td>
            <td> <?php echo $item['price']; ?></td>

        </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
public function get_id($id){
    $query = $this->db->get_where('laptop_notebook', array('id'=>$id))->result();
    $data = $query[0];
    return $data;
查看:

 public function add(){


    $product = $this->emag_model->get_id($this->input->post('product_id'));

    $insert = array(

        'id' =>$product->id,
        'qty'     => 1,
        'price' =>$product->pret,
        'name'    =>  $product->nume,

    );
    $this->cart->insert($insert);

    redirect('emag/chart');
}
public function chart(){
    $this->renders();
      $this->load->view('emag/chart');
}
 <input type="hidden" name="product_id" value="<?php echo $laptop->id; ?> " />  
//$laptop->id retrieves the id of the curent product

 <table id="table_cart">


        <tbody>
        <?php foreach( $this->cart->contents() as $item): ?>
        <tr>
            <td>                   
                <?php echo  $item['name']; ?>
            </td>
            <td><?php echo $item['qty']; ?></td>
            <td> <?php echo $item['price']; ?></td>

        </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
public function get_id($id){
    $query = $this->db->get_where('laptop_notebook', array('id'=>$id))->result();
    $data = $query[0];
    return $data;
我已经自动加载了购物车和会话库,我将
$config['sess\u use\u database']=TRUE;

$config['sess_table_name']='ci_sessions'我创建了ci_sessions表,但仍然不起作用。有什么想法吗?

成功插入购物车的注意事项:

  • 价格
  • “name”(或类似字段)最好不要使用unicode

不知何故,我不知道为什么,
$this->input->post('product_id')
是个问题,即使当我回显它时,我得到了正确的产品id

检查你的$insert它是否有正确的值此控制器或型号是哪个文件??一些codeigniter购物车指南:@saty,控制器请提交你的全部代码!!