如何在Yii2验证规则消息中放置换行符 [英] How to put line-breaks in Yii2 validation rules messages
本文介绍了如何在Yii2验证规则消息中放置换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要破坏Yii2验证规则中使用的一条长消息.
I need to break a long message used in Yii2 validation rule.
我尝试过这样:
public function rules()
{
return [
['username', 'required', 'message' => 'long message first line here'."<br>".PHP_EOL.'long message last line here'],
];
}
,但是<br>
出现在消息中,并且该行没有在我需要的位置中断.
but the <br>
appears in the message and the line doesn't break where I need.
请清楚,我得到的是:
long message first line here<br>long message last line here
而不是:
long message first line here
long message last line here
任何人都可以提供帮助吗?我真的会很感激!预先谢谢你.
Anyone who can help with this? I'd be really grate! Thank you in advance.
推荐答案
我已经解决了将其添加到ActiveForm :: begin
I have solved adding this to ActiveForm::begin
<?php $form = ActiveForm::begin([
'fieldConfig' => [
'errorOptions' => ['class' => 'help-block', 'encode' => false],
],
]); ?>
和一个简单的<br />
[['username'], 'required', 'message' => 'long message first line here <br />long message last line here'],
这篇关于如何在Yii2验证规则消息中放置换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文