I am using ion auth to create a login system for my codeigniter application. I have created routes for better URLs so that for example;
http://localhost/myApplication/index.php/auth/login
is now
http://localhost/myApplication/index.php/login
The "routing rule" i am using to achieve this is
$route['login'] = 'auth/login';
and it is working fine, i.e typing it directly in the browser's address bar takes me to the log in page. The problem occurs when logging in. When i click on the log in button, i get directed back to
http://localhost/myApplication/index.php/auth/login
where of course i get a "404 page Not Found" error. I cannot figure out which part of ion auth is causing this behavior. I have checked the login()
method of the auth.php
controller and nothing there (as far as i can see) is the culprit.
My routes.php looks like this;
$route['default_controller'] = "pages/view";
$route['404_override'] = '';
$route['login'] = 'auth/login';
$route['register'] = 'auth/create_user';
$route['(:any)'] = 'pages/view/$1';
and the 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);
}
}
I appreciate any views that may help shed a light on this mystery. Thank you.
You need to open views/auth/login.php
and change
<?php echo form_open("auth/login");?>
To:
<?php echo form_open("login");?>