如果管理員正在登錄,我希望他去管理員/儀表板。否則傳遞給用戶儀表板。登錄的控制器是按照。在用戶表中,我有一列'角色',值爲'1'和'2'。 1代表管理員,2代表用戶。並有獨立的角色表。根據代碼點火器中的用戶角色重定向到管理員和用戶
用戶登錄功能
public function login(){
$data['title'] = 'Login';
//validating form
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if($this->form_validation->run() ===FALSE){
$this->load->view('templates/header');
$this->load->view('users/login', $data);
$this->load->view('templates/footer');
}else{
//Get username
$username = $this->input->post('username');
//Get password in md5
$password= md5($this->input->post('password'));
//Login User.... passing username and password
$user_id = $this->user_model->login($username, $password);
//checking userid
if($user_id){
//creating session if user_id is present
$user_data=array(
'user_id'=>$user_id,
'username'=>$username,
'logged_in' => true
);
$this->session->set_userdata($user_data);
//set message
$this->session->set_flashdata('user_loggedin', 'Login successful');
redirect('posts');
}else{
//creating session if user_id is not present
$this->session->set_flashdata('login_failed', ' Invalid credentials');
redirect('users/login');
}
}
}
讓我看看你的登錄()方法。 – molagbal
其中是user_role字段?你沒有把它放在會話中嗎? –
你可能會發現這有助於:[點擊這裏](https://stackoverflow.com/questions/41529588/what-is-the-best-practice-for-role-based-login-system-in-codeigniter) –