如何在Yii 2验证错误消息中添加自定义链接?

The*_*der 3 php yii yii-components yii2 yii2-advanced-app

我想在基于Yii 2模型的验证消息中添加自定义链接.

我目前正在使用以下代码块 -

public function rules()
{
  return [
    ['email', 'required'],
    ['email', 'email'],
    ['email', 'unique', 'targetClass' => '\common\models\User', 
                        'message' =>   'Email address has already been taken.'],
  ];
}
Run Code Online (Sandbox Code Playgroud)

我希望此消息显示如下 -

" 已经收到电子邮件地址.已经注册了?然后登录这里."

我怎样才能做到这一点?

Ton*_*ony 6

如注释中所述,您需要在message参数中添加链接,并且还要防止链接被编码,您需要将encode参数设置为false.

$form->field($model, 'email', ['errorOptions' => ['class' => 'help-block' ,'encode' => false]])->textInput()
Run Code Online (Sandbox Code Playgroud)