in old Yii I was using
<?php echo $form->labelEx($model,'text').'<span class="required">* </span>'); ?>
What should I use in yii2 for labeling ?
in old Yii I was using
<?php echo $form->labelEx($model,'text').'<span class="required">* </span>'); ?>
What should I use in yii2 for labeling ?
On
You can use this in css instead of modifying code.
div.required label:after {
content: " *";
color: red;
}
That was discussed here: https://github.com/yiisoft/yii2/issues/2056
The
Yii2's way is like below:So yours would be something like below:
Please note that you need to add
use yii\helpers\Html;in your View. Otherwise, you need to replaceHtml::withyii\helpers\Html::.Update
For those who suffer from
requiredcss class added automatically to parentDIVof a form field:You can remove it like below:
Please note that, this applies to your whole form. So whole form has no required
cssclass. You need to write it for each field by yourself.