2016-11-07 95 views
0

需要更改默認YII錯誤總結,如何自定義誼defualt錯誤彙總到單個錯誤

enter image description here

要顯示在特定形式字段中的每個錯誤如下圖像。

enter image description here

這裏是我的worklet屬性()。

public function properties() { 
    return array(
     'action' => url('/user/signup', array('dialog' => isset($_GET['dialog']) ? $_GET['dialog'] : 0)), 
     'elements' => array(
      'firstName' => array('type' => 'text'), 
      'lastName' => array('type' => 'text'), 
      'email' => array('type' => 'text'), 
      'password' => array('type' => 'password'), 
      'passwordRepeat' => array('type' => 'password'), 
      'profile' => wm()->get('user.profile.helper')->form(), 
      '<hr />', 
      'termsAgree' => array(
       'type' => 'checkbox', 
       'layout' => "<fieldset>{input}\n{label}\n{hint}\n{error}</fieldset>", 
       'uncheckValue' => '', 
       'required' => false, 
       'afterLabel' => '', 
      ), 
     ), 
     'buttons' => array(
      'submit' => array('type' => 'submit', 
       'id'=>'signUpButton', 
       'label' => $this->t('Sign Up')), 
     ), 

     'model' => $this->model 
    ); 
} 

這裏是我的規則()爲模型:

public function rules() 
    { 
     return array(
      array('email, password, passwordRepeat, firstName, lastName', 'required'), 
      array('firstName, lastName, email', 'length', 'max' => 250), 
      array('email', 'email'), 
      array('email', 'unique', 'className' => 'MUser', 'message' => $this->t('This email is already in use.')), 
      array('password', 'length', 'min' => 6), 
      array('passwordRepeat', 'compare', 'compareAttribute'=>'password'), 
      array('termsAgree', 'required', 'message' => $this->t('You must be agree to our Terms of Use and Privacy Policy to join this site.')) 
     ); 
    } 
+0

請發佈一些代碼..我們無法幫助您無代碼 – Blueblazer172

+0

在這裏查看官方[docu](http://www.yiiframework.com/doc-2.0/guide-input-validation.html#validating-輸入) – Blueblazer172

+0

這個問題是針對Yii1還是Yii2? – scaisEdge

回答

0

你可以在規則

 array('email, password, passwordRepeat, firstName, lastName', 'required', 
       'message'=>'{attribute} cannot be blank, please enter a value .'), 

添加一條消息,在您控制器尋找

public function actionError() 
{ 
    if($error=Yii::app()->errorHandler->error) 
    {   
    if(Yii::app()->request->isAjaxRequest) { 
    echo $error['message']; 
    } 
    else 
    $this->render('error', $error); 
    } 
} 

並且需要更換