以下是我的配置设置: -
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'tbl_ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update'] = 300;
这是一个ajax函数: -
$('#add_to_cart').on('click',function(){
var rowseat = $('#rowseat').val();
var movieprice = $('#movie_price').val();
var moviename = $('#movie_name').val();
var movieid = $('#movie_id').val();
$.ajax({
type: "POST",
url: "<?php echo base_url();?>ajax/add_to_cart",
data: {'movieid':movieid,
'moviename':moviename,
'movieprice':movieprice,
'rowseat':rowseat},
dataType: 'json',
success: function (data) {
if(data.status==1)
{
alert("Tickets added to cart");
location.href="<?php echo base_url();?>cart";
}
else
{
alert("Cart addition failed");
}
}
});
});
这个ajax函数调用这个php控制器函数: -
include_once('common.php');
class Ajax extends Common {
function __construct()
{
parent::__construct();
$this->load->model('oracle_model');
}
function add_to_cart()
{
if($this->input->post('movieid'))
{
$movieid = $_POST['movieid'];
}
if($this->input->post('moviename'))
{
$moviename = $_POST['moviename'];
}
if($this->input->post('movieprice'))
{
$movieprice = $_POST['movieprice'];
}
if($this->input->post('rowseat'))
{
$rowseat = $_POST['rowseat'];
}
$rowseatArr = explode(",",$rowseat);
foreach($rowseatArr as $rArr)
{
$cart['rowseat'] = $rArr;
$cart['price'] = $movieprice;
$cart['movie_name'] = $moviename;
$cart['movie_id'] = $movieid;
$cartTicket[] = $cart;
}
$return = $this->cart_model->validate_add_cart_item($cartTicket);
if($return == 1)
{
$respond['status'] = 1;
$respond['message'] = 'test';
}
else
{
$respond['status'] = 0;
$respond['message'] = 'test';
}
echo json_encode($respond);
}
这是我的cart_model函数,它是:
function validate_add_cart_item($cartArr)
{
$cartTicket = 0;
$totalTicket = count($cartArr);
foreach($cartArr as $ca)
{
$qty = 1; // Assign posted quantity to $cty
$price = $ca['price'];
$rowseat= $ca['rowseat'];
$movie_name= $ca['movie_name'];
$movie_id = $ca['movie_id'];
$rowArr = explode("_",$rowseat);
$name = 'Row'.$rowArr[0].'Seat'.$rowArr[1];
$id = $movie_id.'-'.$rowArr[0].'-'.$rowArr[1];
$data = array(
'id' => $id,
'qty' => $qty,
'price' => $price,
'name' => $name,
'options' => array('movie'=>$movie_name,'row'=>$rowArr[0],'seat'=>$rowArr[1],
'date'=>date('d-m-Y'),
'showtime_id'=>'',
'showtime'=>'')
);
if($this->cart->insert($data))
{
$cartTicket++;
}
}
if($totalTicket == $cartTicket)
return 1;
else
return 0;
}
正如我们所看到的,成功时javascript ajax功能会重定向到购物车控制器。
include_once('common.php');
class Cart extends Common {
function __construct()
{
parent::__construct();
$this->load->model('oracle_model');
}
public function index()
{
print_r($this->cart->contents());
}
}
这是common.php控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Common extends CI_Controller {
protected $_data = array();
protected $_globalCompanyList = array();
public $oracleDB = array();
public $_limit = 10;
public $_ousername = 'xxxxxx';
public $_password = 'xxxxxxx';
public $_localhost = 'xxxxxxx';
public function __construct() {
parent::__construct();
@session_start();
$this->load->helper(array('url','form','html'));
$this->load->library(array('authentication','upload','image_lib','pagination'));
//$this->lang->load('webpage','dutch');
}
}
重定向到购物车控制器后,购物车显示为空白,即使数据已保存在tbl_ci_sessions
表格中。
CREATE TABLE tbl_ci_sessions (session_id varchar2(40) PRIMARY KEY,
ip_address varchar2(16) NOT NULL,
user_agent varchar2(500) NOT NULL,
last_activity number(10) NOT NULL,
user_data varchar2(4000)
);
我做错了什么?顺便说一句,我正在使用带有codeigniter的oracle 10g快速版。