我想在控制器中设置会话并访问方法中的会话数据。谁能告诉我一种实现方法?下面是我的代码块
if ($data['result'] = $this->Webmanager_model->admin_login($credential)) {
foreach ($data['result'] as $val) {
$credentials = array(
'adminid' => $val->admin_id,
'name' => $val->name,
'username' => $val->username);
}
$this->session->adminid = $val->admin_id;
$this->session->name = $val->name;
$this->session->username = $val->username;
$this->load->view('dashboard1');
} else {
echo "access denied";
}
通过这种方式,我可以设置会话,但在下一个方法中显示为空。
答案 0 :(得分:0)
if($data['result'] = $this->Webmanager_model->admin_login($credential))
{
foreach ($data['result'] as $val)
{
$credentials=array('adminid'=>$val->admin_id,
'name'=>$val->name,
'username'=>$val->username);
}
// Set Session
$this->session->set_userdata("login_detail",$credentials);
$this->load->view('dashboard1');
} else {
echo "access denied";
}
// Get session;
$sessionArray=$this->session->userdata("login_detail");