2011-09-29 42 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