如何在 Yii 2 验证错误消息中添加自定义 link?
How to add custom link in Yii 2 validation error message?
我想在基于 Yii 2 模型的验证消息中添加自定义 link。
我目前正在使用以下代码块-
public function rules()
{
return [
['email', 'required'],
['email', 'email'],
['email', 'unique', 'targetClass' => '\common\models\User',
'message' => 'Email address has already been taken.'],
];
}
我希望此消息显示如下-
"Email address is taken. Already registered? Then log-in here."
我怎样才能做到这一点?
如评论中所述,您需要将 link 添加到 message
参数中,同时为了防止 link 被编码,您需要设置 encode参数为false.
$form->field($model, 'email', ['errorOptions' => ['class' => 'help-block' ,'encode' => false]])->textInput()
我想在基于 Yii 2 模型的验证消息中添加自定义 link。
我目前正在使用以下代码块-
public function rules()
{
return [
['email', 'required'],
['email', 'email'],
['email', 'unique', 'targetClass' => '\common\models\User',
'message' => 'Email address has already been taken.'],
];
}
我希望此消息显示如下-
"Email address is taken. Already registered? Then log-in here."
我怎样才能做到这一点?
如评论中所述,您需要将 link 添加到 message
参数中,同时为了防止 link 被编码,您需要设置 encode参数为false.
$form->field($model, 'email', ['errorOptions' => ['class' => 'help-block' ,'encode' => false]])->textInput()