当我检查CI的添加到购物车内置功能时,我在我的实时服务器上遇到问题。但它在我的本地主机上正常工作 这是我的模型代码,我将保存购物车
$id = $this->input->post('product_id'); // Assign posted product_id to $id
$qty = 1;// Assign posted quantity to $cty
$this->db->from($this->table_name);
$this->db->join($this->desc_table_name, "$this->desc_table_name.products_id = $this->table_name.id");
$this -> db -> where('id', $id); // Select where id matches the posted id$this->db->from($this->table_name);
$this -> db -> limit(1);
$query = $this->db->get(); // Select the products where a match is found and limit the query by 1
// Check if a row has been found
if($query->num_rows > 0){
foreach ($query->result() as $row)
{
$data = array(
'id' => $id,
'qty' => $qty,
'price' => $row->price,
'name' => "$row->title",
'options' => array('description' => $row->description,'short_desc'=> $row->short_desc,'image'=>$row->image,),
);
//print_r($data);
$res = $this -> cart -> insert($data);
return TRUE;
}
// Nothing found! Return FALSE!
}else{
return FALSE;
}`
我的ajax功能就像这样
var link = window.location.protocol + "//" + window.location.host + "/youth_fashion/";
$(".add_item").click(function() {
// Get the product ID and the quantity
var id = $(this).attr('id');
$.post(link + "front/cart_controller/add_cart_item1", { product_id: id, ajax: '1' },
function(data){
if(data == 'true'){
$.get(link + "front/cart_controller/show_cart", function(cart){
$("#cart_content").html(cart);
var x = location.href;
window.location.href= x;
});
}else{
alert("Product does not exist");
}
});
return false;
});`
我正在使用CI 2.0。提前谢谢
答案 0 :(得分:0)
问题已解决。
问题出在会话文件(config.php)中。我正在使用购物车库,但它没有将数据存储到表格中
$config['sess_use_database'] = TRUE;
我变成了现实并存储并为我工作