如何在codeigniter中使用$this->session->set_userdata

x6492ojm  于 2022-12-16  发布在  其他
关注(0)|答案(2)|浏览(110)

当我使用$this-〉session-〉set_userdata时,我遇到了一些CI问题
主计长

public function check_login()
{
    $email    = $this->input->post('username_email');
    $password = $this->input->post('passwords');
    $password_encrypt = sha1(md5($password));

    $query = $this->model->check_login($email,$password_encrypt);
    if( $query->num_rows() > 0 )
    {
        $row = $query->row(1);
        $data = array(
          'email'           => $row->email,
          'level_id'        => $row->level_id,
          'id_subunit'      => $row->id_subunit,
        );
        $this->session->set_userdata($data);
        return TRUE;
    }
    else{
        return FALSE;
    }
}

型号

function check_login($email,$password_encrypt)
{
    $db = $this->load->database('default',TRUE);
    $where_email = array('email' => $email, 'password' => $password_encrypt);

    $db->where($where_email);
    $query = $db->get('admin',1);

    return $query;
}

我试着进入这里,获取会话数据

public function home()
{
    $data['level'] = $this->session->userdata('level_id');
    $data['email'] = $this->session->userdata('email');
    $data['id_subunit'] = $this->session->userdata('id_subunit');

    if($data['level'] == 1){
        redirect('admin');
    }
    else if($data['level'] == 2){
        redirect('kuesioner/submited'); 
    }
    /*else{
         redirect('sub_unit/home');
    }*/
}

我的问题是我只能从会话中的阵列获取电子邮件和级别ID
怎么解决呢?

izkcnapc

izkcnapc1#

将会话库加载到控制器或config/autoload. php文件中。

$this->load->library('session');

然后设置会话数据。

$this->session->set_userdata($data);
pzfprimi

pzfprimi2#

也许是逗号

$data = array(
  'email'           => $row->email,
  'level_id'        => $row->level_id,
  'id_subunit'      => $row->id_subunit
);

相关问题