Codeigniter购物车无法插入数据 [英] Codeigniter cart can't insert data
问题描述
我正在向一个代码指示器(HMVC代码指示器)添加一些数据,并显示它,我在主车控制器中使用此方法:
I'm trying to add some data to a codeigniter (HMVC codeigniter) chopping cart and display it, i'm using this method in the main cart controller:
function add_to_cart(){
$this->load->library('cart');
// Get data
$userID = $this->input->post('userID');
$eventID = $this->input->post('eventID');
$tickedID = $this->input->post('tickedID');
// Get ticket data
$this->load->module('ticket');
$ticket_query = $this->ticket->get_where($tickedID);
//echo $this->session->all_userdata();
foreach($ticket_query->result() as $ticket_data){
$ticketPrice = $ticket_data->price;
$ticketCategory = $ticket_data->category;
}
//echo 'tickedID: '.$tickedID.' price: '.$ticketPrice.' category: '.$ticketCategory;
// Add item to cart
$data_items = array(
'id' => $tickedID,
'qty' => 1,
'price' => $ticketPrice,
'category' => $ticketCategory,
'options' => array()
);
$this->cart->insert($data_items);
$cart = $this->cart->contents();
echo '<pre>';
echo print_r($cart);
echo '</pre>';
}
基本上我得到 userID
, eventID
和 tickedID
变量从会话,然后我运行一个查询获得打勾与特定的ID。我运行查询的结果,并从它获取 $ thicketPrice
和 $ ticketCategory
变量。然后,我尝试设置 $ data_items
中的变量以插入购物车本身。 FInally我尝试 echo
护理的内容,我得到的是一个空数组。
Basically i'm getting the userID
, eventID
and tickedID
variables from the session, then I run a query to get the ticked with the specific id. I run through the results of the query and get the $thicketPrice
and $ticketCategory
variables from it. Then I attempt to set the variables in $data_items
to insert in the cart itself. FInally I attempt to echo
the contents of the care and all I get is an empty array.
数据库和购物车库都是自动加载的,并且会话正在使用数据库,他们有 ci_sessions
表。
The session, database and cart libraries are all autoloaded and the sessions are using the database, they have the ci_sessions
table. THe sessions also have an ecrypted key, what is wrong?
推荐答案
注意成功插入购物车:
- 'price'> 0
- 'name'(或类似字段)不适用于unicode
这篇关于Codeigniter购物车无法插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!