我正在使用ion auth为我的codeigniter应用程序创建登录系统。我为更好的URL创建了路由,例如;
http://localhost/myApplication/index.php/auth/login
现在是
http://localhost/myApplication/index.php/login
我用来实现此目的的“路由规则”是
$route['login'] = 'auth/login';
并且工作正常,即直接在浏览器的地址栏中输入它会将我带到登录页面。登录时会出现此问题。当我单击登录按钮时,我会被定向回
http://localhost/myApplication/index.php/auth/login
当然我得到“404找不到页面”错误。我无法弄清楚离子auth的哪一部分导致了这种行为。我检查了login()
控制器的auth.php
方法,其中没有任何内容(据我所知)是罪魁祸首。
我的routes.php看起来像这样;
$route['default_controller'] = "pages/view";
$route['404_override'] = '';
$route['login'] = 'auth/login';
$route['register'] = 'auth/create_user';
$route['(:any)'] = 'pages/view/$1';
和login()
mehod;
//log the user in
function login()
{
$this->data['title'] = "Login";
//validate form input
$this->form_validation->set_rules('identity', 'Identity', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() == true)
{
//check to see if the user is logging in
//check for "remember me"
$remember = (bool) $this->input->post('remember');
if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember))
{
//if the login is successful
//redirect them back to the home page
$this->session->set_flashdata('message', $this->ion_auth->messages());
redirect('/', 'refresh');
}
else
{
//if the login was un-successful
//redirect them back to the login page
$this->session->set_flashdata('message', $this->ion_auth->errors());
redirect('auth/login', 'refresh'); //use redirects instead of loading views for compatibility with MY_Controller libraries
}
}
else
{
//the user is not logging in so display the login page
//set the flash data error message if there is one
$this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');
$this->data['identity'] = array('name' => 'identity',
'id' => 'identity',
'type' => 'text',
'value' => $this->form_validation->set_value('identity'),
);
$this->data['password'] = array('name' => 'password',
'id' => 'password',
'type' => 'password',
);
$this->_render_page('login', $this->data);
}
}
我感谢任何可能有助于揭示这个谜团的观点。谢谢。
答案 0 :(得分:2)
您需要打开views/auth/login.php
并更改
<?php echo form_open("auth/login");?>
要:
<?php echo form_open("login");?>