首页 > 解决方案 > 将html转换成yii2格式

问题描述

我有以下 html 并且我在我的视图中使用了它,但我希望它是 yii2 格式的。

<label id="rate" for="rate">Rate</label>
<input type="text" style="width: 345px; height: 35px;" name="contact" id="contact" value="" maxlength="255">
<span class="help-text"></span>

标签: htmlyii2

解决方案


<?= $form->field($model, 'contact')->input([
    'template' => '<label id="rate" for="rate">{label}</label>{input}<span class="help-text"> 
</span><div>{error}</div>', 'maxlength' => true, 'id' => 'contact', 'style' => 
'width: 345px; height: 35px;'
])->label('Rate'); ?>



public function rules()
{
return [
     [['contact'], 'string',  'max' => 255],
];
}

推荐阅读