[英]Codeigniter Redirect to a controller
I have different types of users with different functionalities, i want to redirect different users to their controllers,Is this a good practice in Codeigniter if yes how can i do that? 我有具有不同功能的不同类型的用户,我想将不同的用户重定向到他们的控制器。如果可以,这是Codeigniter中的一个好习惯吗?
public function login() {
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() != FALSE) {
$db_data = array();
$db_data['email'] = $this->input->post('email', TRUE);
$db_data['password'] = $this->input->post('password', TRUE);
$res = $this->Fypms_model->auth_user($db_data);
if ($res->result_id->num_rows == 1) {
//$this->session->set_userdata($user);
$res = $res->result();
$this->session->set_userdata('user_id', $res[0]->user_id);
//redirect("users/changepassword");
switch ($res[0]->user_type) {
case "SA":
redirect("/superadmin/index");;
break;
}
} else {
$data['error'] = "Invalid Email or Password";
}
}
}
Put your redirect url in if($res[0]->user_type== 'user type'){redirect("url");}
condition. 将您的重定向网址置于
if($res[0]->user_type== 'user type'){redirect("url");}
条件中。 use elseif($res[0]->user_type== 'user type'){redirect("url");}
followed by first if condition. 使用
elseif($res[0]->user_type== 'user type'){redirect("url");}
然后是第一个if条件。
It depends to your system and your self, if you have huge system that can split into sub systems , you can do it , but if you have little system , you dont need to do that , only manage your user with permissions , and sessions. 这取决于您的系统和您自己,如果您有可以拆分为子系统的庞大系统,则可以做到,但是如果您的系统很少,则不需要这样做,只需使用权限和会话来管理用户。
if you want to use method 1: you must add url helper then you can write easily: 如果要使用方法1:必须添加url helper,则可以轻松编写:
redirect('/controller/method');
in method 2: 在方法2中:
use session to manage users. 使用会话来管理用户。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.