YII2 ActiveForm部分参数说明
YII2 ActiveForm部分参数说明:<?php $form = ActiveForm::begin([
'successCssClass' => 'has-success', // successCssClass
'errorCssClass' => 'has-error', // errorCssClass
'options'=>[
'enctype'=>'multipart/form-data',
'class' => 'form-horizontal',
],
'fieldConfig' => [//统一修改字段的模板
'template' => "{label}\n<div class=\"col-lg-5\">{input}</div>\n<div class=\"col-lg-3\">{error}</div>", //修改显示内容默认为{label}\n{input}\n{hint}\n{error}\n是html代码显示时的换行
'labelOptions' => [
'class' => 'col-lg-2 control-label', //修改label的样式
],
'errorOptions' => [
'encode'=>false,//关闭对models rules的错误提示进行html转义
'data-json' => [//其他参数
'params' => [
'id' => 1,
'name' => 'yii2'
],
'status' => 'ok'
],
'tag' => 'span',//错误提示使用的html标签
'class' => 'help-block',//错误提示使用的css类
]
],
]);
?>
再结合models rules可以实现错误提示加图标等
public function rules()
{
return [
['name', 'validateCountry'],
[['code', 'name'], 'required','message' => '<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>{attribute}出错了'],
[['name'], 'trim'],
[['population'], 'integer'],
[['code'], 'string', 'max' => 2],
[['name'], 'string', 'max' => 52]
];
}
models rules小备注:http://www.phpin.net/thread-353-1-1.html
页:
[1]