在代码点火器中,我要从一个登录页面登录3个不同角色的不同用户,该登录页面的用户名和密码在我的控制器中使用“ if elseif&else”显示在不同的db表中,我认为如果表单验证是正确的,它将转到if and if if not coorect时,它将转到elseif,如果不起作用,它将转到第三位,即m_faculty,如果它也没有起作用,则它将显示警报,提示您您输入了错误的ID和密码,如果否则,我只能重定向到“ faculty / m_dashboard”,这是我的教师仪表板,其他重定向在知道为什么不起作用或执行此操作的任何更好方法时均无效。 ?????
public function Auth()
{
$rules = array(
array('field' => 'username', 'label' => 'Username', 'rules' => 'required'),
array('field' => 'password', 'label' => 'Password', 'rules' => 'required'),
);
$this->form_validation->set_rules($rules);
if ($this->form_validation->run() == false) {
$Msg = array('Msg' => validation_errors(), 'Type' => 'danger');
$this->session->set_flashdata($Msg);
redirect(base_url() . 'Admin/');
}
# faculty dashboard dashboard
elseif ($this->form_validation->run() == true)
{
$username = $this->lib->validate($this->input->post('username'));
$password = $this->lib->validate($this->input->post('password'));
$username = $this->security->xss_clean($username);
$password = $this->security->xss_clean($password);
$count = $this->lib_model->Counter('m_faculty', array('username' => $username, 'password' => $password, 'status' => 0));
if ($count == 1) {
$Sessions = array(
'EmpCode' => $username,
'EmpName' => 'Administration',
'ELogin' => true);
$this->session->set_userdata($Sessions);
$Msg = array('Msg' => ' Have a Nice Day ', 'Type' => 'success');
$this->session->set_flashdata($Msg);
redirect(base_url() . 'Faculty/f_dashboard');
}
}
#supervisior dashboard
elseif ($this->form_validation->run() == true)
{
$username = $this->lib->validate($this->input->post('username'));
$password = $this->lib->validate($this->input->post('password'));
$username = $this->security->xss_clean($username);
$password = $this->security->xss_clean($password);
$count = $this->lib_model->Counter('m_supervisior', array('username' => $username, 'password' => $password, 'status' => 0));
if ($count == 1) {
$Sessions = array(
'EmpCode' => $username,
'EmpName' => 'Administration',
'ELogin' => true);
$this->session->set_userdata($Sessions);
$Msg = array('Msg' => ' Have a Nice Day ', 'Type' => 'success');
$this->session->set_flashdata($Msg);
redirect(base_url() . 'Supervisior/supervisior_dashboard');
}
}
#admin dashboard
elseif ($this->form_validation->run() == true)
{
$username = $this->lib->validate($this->input->post('username'));
$password = $this->lib->validate($this->input->post('password'));
$username = $this->security->xss_clean($username);
$password = $this->security->xss_clean($password);
$count = $this->lib_model->Counter('m_admin', array('username' => $username, 'password' => $password, 'status' => 0));
if ($count == 1) {
$Sessions = array(
'EmpCode' => $username,
'EmpName' => 'Administration',
'ELogin' => true);
$this->session->set_userdata($Sessions);
$Msg = array('Msg' => ' Have a Nice Day ', 'Type' => 'success');
$this->session->set_flashdata($Msg);
redirect(base_url() . 'Admin/dashboard');
}
}
#error msg
else {
$Msg = array('Msg' => 'Username and Password Invalid', 'Type' => 'danger');
$this->session->set_flashdata($Msg);
redirect(base_url() . 'Admin/');
}
}