2017-02-14 47 views
0

驗證期間,我可以在yii2中顯示提示嗎? 在我的模型,我有:Yii2驗證時顯示提示

public function rules() 
     { 
      return [ 
       [['content'], 'checkLastCommentDate', 'skipOnEmpty' => false, 'skipOnError' => false], 
      ]; 
     } 

    public function checkLastCommentDate($attribute) 
    { 
     if (true) { 
      //can set hint here? 
     } 
    } 

回答

0

使用型號:: addError方法:

public function checkLastCommentDate($attribute) 
{ 
    if (true) { 
     $this->addError($attribute, 'Here is my hint'); 
    } 
} 
+0

沒有,yii2有類似的提示,但我不能確認使用它。也許它不應該在驗證?我只想顯示提示$ vat == 5 –