2013-12-08 44 views
0

Kohana很新穎,我在php中開發了一段時間。目前我正在嘗試創建一些自定義驗證規則。使用OOTB驗證規則,代碼可以正常工作,但是當兩個自定義驗證規則收到錯誤消息時。Kohana自定義驗證規則錯誤ReflectionException

ReflectionException [ 0 ]: Class Account_Model does not exist 

下面所有的代碼模型中發現所謂的帳戶

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

Account_Model在你的代碼需要Model_Account,那也應該是一流的,這是在名稱。

$valid_post->//other rules 
      ->rule('username', 'Model_Account::unique_username') 
      ->rule('email', 'Model_Account::unique_email')); 
+0

啊我很接近。感謝您抽出寶貴時間來看看。 – user3032973