Reputation: 4977
What is the correct format to add rules to check unique username and email in kohana 3.3
I have tried the followings
array(array($this, 'unique'), array('username', ':value')); // added similar to email also
array('username',array('unique_username'); // / added similar to email also
array('username',array('unique_username',array(':value')); // / added similar to email also
public static function unique_username($username)
{
echo 'running';
// Check if the username already exists in the database
return ! DB::select(array(DB::expr('COUNT(username)'), 'total'))
->from('users')
->where('username', '=', $username)
->execute()
->get('total');
}
I am getting the following error
Argument 3 passed to Kohana_Validation::rule() must be an array, string given
Upvotes: 0
Views: 117
Reputation: 597
I can't give you an exact answer because you don't show your class name. For example, if your class was named Model_User
here's how your would use a static method as a validation callback:
->rule('username', 'Model_User::unique_username', array(':value'));
or
->rule('username', array('Model_User', 'unique_username'), array(':value'));
Upvotes: 1