dongpang2483 2015-07-15 13:45
浏览 46

会话中的codeigniter数组数据

I started to learn codeigniter and now I have one prblem. I am making online store for laptops and now I have a wish to make a cart. I wanna remember all data in session when user add some laptop in cart, redardless is logged or not. But my problem is that I remember in session only last added id of laptops. I managed to remember number of laptops in total, and total price, but can’t manage how to remember all id. I am using next code in controller:

public function adding()
{
    $id_lap=$this->input->post('id_lap');   // id laptop of which was clicked by user
    $num_items=$this->input->post('num_items');  // total number of laptops
    $price=$this->input->post('price');  // total cost

     if($id_lap !='')
     {      
             $this->session->set_userdata('num_items',$num_items);
             $this->session->set_userdata('price_new',$price);
             $this->session->set_userdata('id_lap_new',$id_lap);

             $response=array(
                'status'=>1,
                'num_items'=>$num_items,
                'price_new'=>$price,
                'id_new_lap'=>$id_lap
             );   

     } else {

         $response=array(
            'status'=>0
         );
     }

     echo json_encode($response);
}

I am using Ajax for sending data in controller.

Thanks for answer, I appreciate.

  • 写回答

1条回答 默认 最新

  • dskm94301 2015-07-15 14:13
    关注

    try to save the session in the database, first open your config.php under application folder and change use session database option value to true. Import the sql structure like you have there and use sessions like you have. It will store the session variable in db. You might want to enable session encryption as well.

    评论

报告相同问题?

悬赏问题

  • ¥20 steam下载游戏占用内存
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系