1

我已经定义了自定义验证规则:

['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() 方法中显示链接?

4

1 回答 1

6

将此配置数组传递给 ActiveField

'errorOptions' => ['encode' => false]
于 2015-04-12T19:25:05.273 回答