yii2 ActiveForm field 添加 html 代码

统一修改

$form = ActiveForm::begin([

'fieldConfig' => [

'options'=>['class' => 'weui-cell weui-cell_access'],//修改 {label} 上一层样式
'template' => "<div class='col-sm-3 text-left'>{label}</div><div class='col-sm-9'>{input} {hint} {error}</div>",

'labelOptions' => ['class' => 'weui-label'],//修改label样式
'inputOptions' => ['class' => 'weui-input'],//修改input样式


]
]);

指定修改

原来activeForm field 默认输出的html 代码不能满足项目需求,需要在原来基础上添加其他一些html代码。
例如:<?= $form->field($model, 'username',)->textInput(['value'=>$model->username]) ?>

改成:

<?= $form->field($model, 'username',[
  'template' => "{label} {input} {hint}<p class='fa fa-user'>ssdfsdfd</p> {error}"
])->textInput(['value'=>$model->username]) ?>

{label} {input} {hint}<p class='fa fa-username'>ssdfsdfd</p> {error}

原文地址:https://www.cnblogs.com/jimz/p/9963660.html