嗨,我刚接触ci刚刚登录&登出。当我尝试注销它 显示找不到url / loginController / logout 问题是什么 ?是因为会议还是我错过了什么?
这是我的控制器
<?php
class loginController extends CI_Controller{ /**controller*/
public function index(){
$this->login();
}
public function login(){
$this->load->view('login');
}
public function home(){
if ($this->session->userdata('logged')){
$this->load->view('main');
} else {
redirect('loginController/denied');
}
}
public function denied(){
$this->load->view('denied_page');
}
public function login_validation() /**set rules*/
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('username',
'Username', 'required|min_length[3]|max_length[12]');
$this->form_validation->set_rules('password',
'Password', 'required|sha1|callback_password_check');
if ($this->form_validation->run()){ /** form valdation*/
$data = array(
'username' => $this->input ->post('username'),
'logged' => 1
);
$this->session->set_userdata($data);
redirect('main');
} else {
$this->load->view('login');
}
}
public function logout(){ //login
$this->session->sess_destroy();
redirect('login');
}
public function password_check(){
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->model('users');
if($this->users->log_in($username, $password)){
return True;
}else{
$this->form_validation->set_message('password_check',
'Incorrect username or password.');
return False;
}
}
}
?>
答案 0 :(得分:0)
更改代码
public function logout(){ //login
$this->session->sess_destroy();
redirect('login');
}
到
public function logout(){
$this->session->sess_destroy();
redirect('loginController/login');
}
答案 1 :(得分:-1)
$this->load->helper('url');
,并在验证功能上将$this->load->helper(array('form', 'url'));
更改为$this->load->helper(array('form'));
。重定向时使用base_url()
将第二行redirect('login');
更改为redirect(base_url('/'.get_class($this)));
我希望它有效并帮助您,只需记住阅读this并在注销后通过index()函数访问登录页面。
如果这不起作用只是尝试将base_url()更改为site_url(),但您应该知道它们之间的区别。