Php Ion Auth在登录期间未正确重定向
我正在使用ion auth为我的codeigniter应用程序创建一个登录系统。我已经为更好的URL创建了路由,例如:Php Ion Auth在登录期间未正确重定向,php,codeigniter,routes,ion-auth,Php,Codeigniter,Routes,Ion Auth,我正在使用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
现在是
http://localhost/myApplication/index.php/login
我用来实现这一点的“路由规则”是
$route['login'] = 'auth/login';
它工作正常,也就是说,直接在浏览器的地址栏中输入它会让我进入登录页面。登录时出现问题。当我点击“登录”按钮时,我会被引导回
http://localhost/myApplication/index.php/auth/login
当然,我会得到一个“404页面未找到”错误。我不知道是ion auth的哪一部分导致了这种行为。我已经检查了auth.php
控制器的login()
方法,但那里没有任何东西(据我所知)是罪魁祸首
我的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);
}
}
我很欣赏任何有助于揭开这个谜团的观点。谢谢。您需要打开
视图/auth/login.php
并进行更改
<?php echo form_open("auth/login");?>
致:
答案似乎就在那里,藏在眼前,谢谢@joni。
<?php echo form_open("login");?>