Kohana很新,我在php中开发了一段时间。目前我正在尝试创建一些自定义验证规则。使用OOTB验证规则,代码可以正常工作,但是当我使用两个自定义验证规则时,我收到错误消息。
ReflectionException [ 0 ]: Class Account_Model does not exist
以下所有代码均可在名为Account
的模型中找到public static function unique_username($username)
{
//check to see if username existsin the database
return ! DB::select(array(DB::expr('COUNT(username)'), 'total'))
->from('users')
->where('username', '=', $username)
->execute()
->get('total');
}
public static function unique_email($email)
{
// Check if the email already exists in the database
return ! DB::select(array(DB::expr('COUNT(email)'), 'total'))
->from('users')
->where('email', '=', $email)
->execute()
->get('total');
}
public function validate_new_user($post){
$valid_post = Validation::factory($post);
$valid_post->
->rule('username', 'Account_Model::unique_username')
->rule('email', 'Account_Model::unique_email'));
if ($valid_post->check()) {
return array('error' => false);
} else {
return array('error' => true, 'errors' => $valid_post->errors('default'));
}
}
答案 0 :(得分:0)
Account_Model
必须是Model_Account
,这也应该是它所在类的名称。
$valid_post->//other rules
->rule('username', 'Model_Account::unique_username')
->rule('email', 'Model_Account::unique_email'));