这是我的控制器,用于检查会话是否存在或创建
function guestcart(){
if(!empty($session)){
$seed = 132;
$session = $this->session->userdata($seed);
echo 'Session created';
} else {
$this->session->userdata($seed);
echo 'Session exist ';
}
}
我无法分叉它我是codeigniter的新手
答案 0 :(得分:0)
试试这个:
function guestcart(){
$seed = 132;
if(!empty($this->session->userdata($seed))){
$session = $this->session->userdata($seed);
echo 'Session created';
} else {
$this->session->userdata($seed);
echo 'Session exist ';
}
}
答案 1 :(得分:0)
获取您需要执行的会话数据$this->session->userdata('item'),并检查其值,将其更改为:
function guestcart(){
$session = $this->session->userdata('seed_key');
if(!empty($session)){
echo 'Session exist ';
} else {
$seed = 132;
//set the session data
$session = $this->session->set_userdata('seed_key', $seed);
echo 'Session created';
}
}