2011-09-29 83 views
0

我想将错误消息添加到我的验证对象。Kohana 3.2 Validation_Exception将不支持错误()

它说错误不是Validation_Exception的一种方法。我知道......事情是,我虽然$ e变量将是模型中验证类的实例。我的问题是如何附加错误信息?

错误:

ErrorException [ Fatal Error ]: Call to undefined method Validation_Exception::errors()

控制器:

208    // redirect to the user account 
209    $this->request->redirect('user/profile'); 
210   } catch (Validation_Exception $e) { 
211    // Get errors for display in view 
212    // Note how the first param is the path to the message file (e.g. /messages/register.php) 
213    $errors = $e->errors('register/user'); 
214    // Move external errors to main array, for post helper compatibility 
215    $errors = array_merge($errors, (isset($errors['_external']) ? $errors['_external'] : array())); 
216    $view->set('errors', $errors); 
217    // Pass on the old form values 
218    $_POST['password'] = $_POST['password_confirm'] = ''; 

型号:

$validation = Validation::factory($fields) 
        ->rules('username', $this->_rules['username']) 
        ->rule('username', array($this, 'username_available'), array(':validation', ':field')) 
        ->rules('email', $this->_rules['email']) 
        ->rule('email', array($this, 'email_available'), array(':validation', ':field')) 
        ->rules('password', $this->_rules['password']) 
        ->rules('password_confirm', $this->_rules['password_confirm']); 
        //->labels($_labels); 

      if (Kohana::config('useradmin')->activation_code) { 
        $validation->rule('activation_code', array($this, 'check_activation_code'), array(':validation', ':field')); 
      } 

      if(!$validation->check()) 
      { 
        throw new Validation_Exception($validation, __('Your registering information is not valid.')); 
      } 

我真的不明白为什么这个错误accuring。

+0

[参考 - 这个错误在PHP中意味着什么?](http://stackoverflow.com/q/12769982/367456) – hakre

回答

2

您已经基本回答了您自己的问题 - Validation_Exception没有errors方法。您需要改为从Validation对象调用它。

+0

那么我可以抛出一个异常? – jnbdz

+1

Validation_Exception。然后使用$ e-> array-> errors()。 – Darsstar