I am verifying the email in database in form validation in CodeIgniter by using callback in rule. For example
$this -> form_validation -> set_rules( 'email', 'Email address', 'trim|valid_email|callback_email_exists' );
The email_exists function is:
public function email_exists($email)
{
$this -> load -> model('account_model');
$exists = $this -> account_model -> email_registered( $email );
if ( $exists == true )
{
$this -> form_validation -> set_message ( 'email_exists', 'Email already exists.');
return false;
}
return true;
}
It works fine. However, shouldn’t the above email_exists function be a private function instead of public?
I try to make it private like private function _email_exists($email) and i call back it by callback__email_exists
However I get the error:
Fatal error: Call to private method Account::_email_exists() from context 'CI_Form_validation' in ....(line number)
Can someone tell me what’s wrong?
If you need to call it from outside the object (whether as callback or directly) it should be public