[eluser]Chris Newton[/eluser]
So, I'm having a little trouble using MY_validation... and I've used it before, so I'm not sure what's going on here. Everytime I try to access a method in a model using MY_validation syntax, I get the "Unable to access an error message corresponding to your field name" message, and thusfar I've been unable to figure out why.
In the login_page controller, I call the callback_users_model->check_email_exists callback. I've checked, and it's being called.
One thing to note: according to Wiredesignz, passing "$this" during the $this->validation->run() method is optional, but in my case, if I don't pass $this, I get an error condition "Missing argument 1 for MY_Validation::run(),"
Any ideas? I can't figure out what about this usage of MY_Validation would cause this, when previous uses have worked fine.
Controller Code.
Code:
function login()
{
$this->load->library('validation');
$this->load->library('encrypt');
$this->load->model('sessions_model');
$this->load->model('flashdata_model');
$this->load->model('users_model');
$this->load->helper(array('form','cookie','html','url'));
// The line in question
$rules['login_box_username'] = 'trim|required|min_length[5]|max_length[300]|htmlentities|callback_users_model->check_email_exists[login_box_username]';
$rules['login_box_password'] = 'trim|required|min_length[5]|max_length[300]|htmlentities';
$rules['login_box_remember'] = 'trim';
$this->validation->set_rules($rules);
$fields['login_box_username'] = 'email address';
$fields['login_box_password'] = 'password';
$fields['login_box_remember'] = 'remember me';
$this->validation->set_fields($fields);
if ($this->validation->run($this)===FALSE)
{
$this->load->view('view_login');
}
else
{
$email = $this->input->post('login_box_username');
$password = $this->input->post('login_box_password');
$success = $this->bn_auth->try_login(array('email_address'=>$email),$password);
if ($success)
{
$this->sessions_model->get_id();
$this->sessions_model->db_set('user_id',$this->sessions_model->get('user_id'));
$this->flashdata_model->set('success_message', 'Login was successful');
if (isset($location))
{
redirect($location,'refresh');
}
else
{
redirect(index_page(),'refresh');
}
}
else
{
$this->flashdata_model->set('error_message', 'Your password was not recognized, please try logging in again');
redirect('login_page/login','refresh');
}
}
}
Model Code
Code:
public function check_email_exists($email,$field)
{
$this->load->library('validation');
if ($this->_check_exists($email,'email_address'))
{
return TRUE;
}
else
{
$classname=get_class($this);
$this->validation->set_message($classname.'->check_email_exists', "%s {$email} is not registered, please try another email address");
return FALSE;
}
}