简体   繁体   English

yii2 ActiveForm字段添加html代码

[英]yii2 ActiveForm field add html code

I have this code in Yii2: 我在Yii2中有这个代码:

<?= $form->field($model, 'username',$opzioni)->textInput(array('placeholder' => 'Username'));  ?>

generate this: 生成这个:

<div class="input-icon field-loginform-username required">
    <label class="control-label" for="loginform-username">Username</label>
    <input id="loginform-username" class="form-control" type="text" placeholder="Username" name="LoginForm[username]">
    <div class="help-block"></div>
</div>

and i want to do this 我想这样做

<div class="input-icon field-loginform-username required">
    <label class="control-label" for="loginform-username">Username</label>
    **<i class="fa fa-user"></i>**
    <input id="loginform-username" class="form-control" type="text" placeholder="Username" name="LoginForm[username]">
    <div class="help-block"></div>
</div>

It's possible with the original source? 原始来源可能吗?

refering to http://stuff.cebe.cc/yii2docs/yii-widgets-activefield.html# $template-detail 参考http://stuff.cebe.cc/yii2docs/yii-widgets-activefield.html# $ template-detail

template = "{label}\n{input}\n{hint}\n{error}"

your code should be like this: 你的代码应该是这样的:

<?= $form->field($model, 'username', [
  'template' => "{label}\n<i class='fa fa-user'></i>\n{input}\n{hint}\n{error}"
])->textInput(array('placeholder' => 'Username'));  ?>

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

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