I have created a Validation library modification which allows callbacks into Models.
Save the existing Validation library as MY_validation with only the original run() function in it.
Alter the class identifier to MY_ validation and extend it off CI_Validation.
Change this code appropriatley:
// Call the function that corresponds to the rule
if ($callback === TRUE)
{
//Allows callbacks into Models
if (strpos($rule, '->'))
{
list($class, $method) = split('->', $rule);
if ( ! method_exists($this->CI->$class, $method))
{
continue;
}
$result = $this->CI->$class->$method($_POST[$field], $param);
}
else
{
if ( ! method_exists($this->CI, $rule))
{
continue;
}
$result = $this->CI->$rule($_POST[$field], $param);
}
//Original code continues
// If the field isn't required and we just processed a callback we'll move on…
if ( ! in_array('required', $ex, TRUE) AND $result !== FALSE)
{
continue 2;
}
}
else ....my validation callback declaration then becomes:
$rules['username'] => ‘trim|required|callback_users_model->is_unique[username]’;