3 回答
TA贡献1735条经验 获得超5个赞
在构造函数中加载会话库。
您的代码就像
class Login_c extends MY_controller {
public function index() {
$this->load->helper('form');
$this->load->view('public/admin_login_v');
}
public function __construct(){
parent::__construct();
$this->load->library('session');
}
public function admin_login() {
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'User name', 'required|trim|alpha');
$this->form_validation->set_rules('password', 'Password' , 'required');
if($this->form_validation->run()) {
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->model('login_model');
$login_id = $this->login_model->login_valid($username,$password);
if( $login_id ){
$this->session->set_userdata('user_id', $login_id);
return redirect('admin_c/dashboard');
} else {
echo "user not authenticated";
}
} else {
$this->load->view('public/admin_login_v');
// echo validation_errors();
}
}
}
**请勿在使用redirect()之前进行任何打印**
- 3 回答
- 0 关注
- 166 浏览
添加回答
举报