0
我試圖表現出成功的消息就像$this->addError($attribute, 'Invalid Promo Code');
這個代碼,但無法做到這一點,有沒有辦法來實現這一功能: 我的模型代碼:添加成功的消息只是想添加錯誤Yii2
public function rules()
{
return [
['referralCode', 'validateReferralCode'],
];
}
這是功能驗證:
public function validatePromoCode($attribute, $params){
if ($this->$attribute != '') {
$model = PromoCode::find()
->where(['promo_code'=>$this->promoCode,'status'=>1])
->andWhere('end_date<='.time())->one();
if(!$this->hasErrors() && ($model))
{
// want to add success message here
$this->addSuccess($attribute, 'You will get 20 points');
return true;
}else{
$this->addError($attribute, 'Invalid Promo Code');
}
}
return $this->referralCode;
}