【问题标题】:Kohana error for custom validation rule ReflectionException自定义验证规则 ReflectionException 的 Kohana 错误
【发布时间】: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


    【解决方案1】:

    您的代码中的Account_Model 必须是Model_Account,这也应该是该类的名称。

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

    【讨论】:

    • 啊,我很接近。感谢您花时间查看。
    猜你喜欢
    • 2012-03-24
    • 2016-12-04
    • 2016-10-21
    • 2021-12-09
    • 1970-01-01
    • 2017-07-25
    • 2016-12-12
    • 2015-09-07
    • 1970-01-01
    相关资源
    最近更新 更多