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.