我会在codeigniter中设置一个会话值
$sess_array = array(
'id' => $row->Login_Id,
'username' => $row->Login_Name,
'postid'=> $row->Fk_Post_Id,
);
$CI->session->set_userdata('logged_in', $sess_array);
然后如何检索特定(说 - id)会话值。我试过这些
$createdby=$this->session->userdata('id');
$createdby=$this->session->userdata($logged_in['id']);
但失败了。
答案 0 :(得分:12)
使用数组语法。像,
$this->session->userdata['logged_in']['id'];
答案 1 :(得分:4)
像这样设置
$sess_array = array(
'id' => $row->Login_Id,
'username' => $row->Login_Name,
'postid' => $row->Fk_Post_Id,
);
$CI->session->set_userdata($sess_array);
要检索
$createdby = $this->session->userdata('id');
答案 2 :(得分:3)
$createdby = $this->session->userdata(logged_in['id']);
或
$createdby = echo $_SESSION[logged_in['id']];
答案 3 :(得分:3)
$sess_array = array(
'id' => $row->Login_Id,
'username' => $row->Login_Name,
'postid'=> $row->Fk_Post_Id,
);
$CI->session->set_userdata('logged_in', $sess_array);
然后
$logged_in = $this->session->userdata('logged_in');
$createdby = $logged_in['id'];
答案 4 :(得分:3)
Session write process. session content could be dynamic value
$logged_in = [
'id'=> 1,
'name'=> 'test'
];
Particular Session retrieve process.
$this->session->userdata['logged_in']['id'];
答案 5 :(得分:2)
$pdata = array(
'id' => $row->Login_Id,
'username' => $row->Login_Name,
); // pass ur data in the array
$this->session->set_userdata('session_data', $pdata); //Sets the session
$pdata = $this->session->userdata('session_data'); //Retrive ur session
$pdata['id'] will give u the corresponding id
答案 6 :(得分:1)
在较新版本中,您只需使用
即可$this->session->username
$this->session->id
$this->session->postid