简体   繁体   English

Yii2:如何使验证规则消息不被编码?

[英]Yii2: How to make validation rule message not to be encoded?

In base PasswordResetRequestForm model: 在基础PasswordResetRequestForm模型中:

public function rules()
    {
        return [               
            ['email', 'exist',
                'targetClass' => '\common\models\User',
                'filter' => ['status' => User::STATUS_ACTIVE],
                'message' => 'Such user is not registered. '.BaseHtml::a('Signup.',['site/signup'])
            ],
        ];
    }

But link renders encoded. 但链接渲染编码。 How to force it not to be encoded? 如何强制它不被编码? Where should I do it, in ActiveForm, in field config, or in validation rule? 我应该在ActiveForm,字段配置或验证规则中的哪个位置执行此操作?

I don't know about the past, but now you can configure it in the fieldConfig: 我不知道过去,但现在你可以在fieldConfig中配置它:

$form = ActiveForm::begin([
    'fieldConfig' => [
        'errorOptions' => ['encode' => false],
    ],
]);

You can configure this on ActiveForm : 您可以在ActiveForm上配置它:

<?php $form = ActiveForm::begin([
    'encodeErrorSummary' => false,
]); ?>

Read more : http://www.yiiframework.com/doc-2.0/yii-widgets-activeform.html#$encodeErrorSummary-detail 阅读更多: http//www.yiiframework.com/doc-2.0/yii-widgets-activeform.html#$encodeErrorSummary-detail

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM