[eluser]silverback[/eluser]
Hi,
What is the best way to pass error statuses?
For example, I have a user controller which has a login method, and a validate_login method:
Code:
function login($error = 0)
{
$data = array(
'title' => 'Login',
'main_content' => 'login_view',
'error' => $error
);
$this->load->view('includes/template', $data);
}
function validate_login()
{
$error = $this->user_model->validate_login();
if ($error < 0)
{
$this->login($error);
} else
{
redirect('somepage');
}
}
user_model->validate_login() checks that the form data is correct with form validator, and then checks the username/password against the DB (returns -1 and -2 respectively). If I were just checking the form data, there would be no need to pass error statuses, but I want to display a message if the login details are incorrect.
While the above works fine, it doesn't seem particularly elegant and I wanted to ask if there is a standard way of doing this?
Thanks