我已经定义了自定义验证规则:
['Email', 'checkUniqueExistence'],
public function checkUniqueExistence($attribute, $params)
{
$email = $this->$attribute;
$checkUniqueExistenceForEmail = Parents::find()->where([ 'Email' => $email])->One();
$resendActivationLink = Html::a('Resend Link','#');
if(count($checkUniqueExistenceForEmail) > 0){
if($checkUniqueExistenceForEmail->IsAccountActivated == Yii::$app->params['IsAccountActivatedTrue']){
$this->addError($attribute, 'Email address already exists');
}
else{
$this->addError($attribute, 'You haven\'t activated your account. Request '.$resendActivationLink);
}
}
}
但链接不会生成。它显示为一个字符串。提交表单后,我得到了以下输出:
You haven't activated your account. Request <a href="#">Resend Link</a>
是否可以在addError()方法中显示链接?
答案 0 :(得分:6)
将此配置数组传递给ActiveField
'errorOptions' => ['encode' => false]