【发布时间】:2013-12-08 18:16:08
【问题描述】:
对 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'));
}
}
【问题讨论】:
标签: php validation kohana