html - 将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>
解决方案
<?= $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],
];
}
推荐阅读
- c++ - 从作为模板参数传递的 const 类型继承
- amazon-web-services - 在 VPC 中以编程方式获取 AWS ES 终端节点
- r - 如何在 sparklyr 中训练 ML 模型并预测另一个数据帧上的新值?
- windows - 禁用自动登录 Windows 7(以及缺少帐户图标)
- c# - 自更新 WPF 应用程序,启动器进程通过反射加载 WPF 应用程序
- vba - 保护工作表时出现 VBA 运行时错误 1004
- npm - 在 npm 上构建错误
- python - 如何将同一篇文章中的文本附加到一个字符串中?美汤
- .net - 该地址的主机名无效:infinitebankoftheuniverse@gmail.com
- windows - Windows CPU 温度