yii中form组件的创建
程序员文章站
2022-03-27 10:31:50
1.引入组件use yii\widgets\ActiveForm;2.创建组件
1.引入组件
use yii\widgets\ActiveForm;
2.创建组件
<?php
/**
* Created by PhpStorm.
* User: Hansn cz P03
* Date: 17/11/17
* Time: 9:56
*/
use yii\helpers\Url;
use yii\widgets\ActiveForm;
use common\components\Leohowl;
use backend\components\FilePicker\FilePicker;
use backend\components\AddChip\AddChipWidget;
$model['uuid'] = isset($model['uuid']) ? $model['uuid'] : Leohowl::createRandomString(6);
$model['type'] = isset($model['type']) ? $model['type'] : 'HTFC(DT)-I';
$model['status'] = isset($model['status']) ? $model['status'] : 1;
$model['orders'] = isset($model['orders']) ? $model['orders'] : 100;
if($type === 'add'){
$template = [
'action' => '添加',
'url' => Url::toRoute(['/fan/add'])
];
} else {
$template = [
'action' => '更新',
'url' => Url::toRoute(['/fan/edit', 'uuid'=>$model['uuid']])
];
}
$this->title = "风机管理";
$this->params['breadcrumbs'][] = ['label'=>'风机管理'];
$this->params['breadcrumbs'][] = ['label'=>'风机列表', 'url'=>Url::toRoute(['/fan/list'])];
$this->params['breadcrumbs'][] = ['label'=>$template['action'].'风机详情'];
$this->params['page_title'] = $template['action'].'风机详情';
$this->registerJsFile(DIST.'/script/ueditor/ueditor.config.js', ['depends' => backend\assets\AppAsset::className(), "position"=> $this::POS_END]);
$this->registerJsFile(DIST.'/script/ueditor/ueditor.all.js', ['depends' => backend\assets\AppAsset::className(), "position"=> $this::POS_END]);
?>
<div class="box box-solid">
<div class="box-body">
<?php
$form = ActiveForm::begin([
'id'=>'cms-fan',
'action'=>$template['url'],
'method'=>'post',
'fieldConfig'=>[
'template'=>'<div class="form-group input-group"><div class="col-lg-3">{label}</div><div class="col-lg-7">{input}</div></div>',
'inputOptions' => ['class' => 'form-control'],
],
])
?>
<div class="col-lg-12">
<?=
$form
->field($model, 'uuid',['template'=>'{input}'])
->textInput(['maxlength' => 16,'type'=>'text'])
->hiddenInput()
->label(false)
?>
<?=
$form
->field($model, 'type')
->textInput(['maxlength' => 128,'type'=>'text'])
->label('<span class="required">*</span>风机型号',['class'=>'input-group-addon'])
?>
<?=
$form
->field($model, 'num')
->textInput(['type'=>'text'])
->label('<span class="required">*</span>型号数',['class'=>'input-group-addon'])
?>
<?=
$form
->field($model, 'volume')
->textInput(['type'=>'text'])
->label('<span class="required">*</span>风量',['class'=>'input-group-addon'])
?>
<?=
$form
->field($model, 'pa')
->textInput(['type'=>'text'])
->label('<span class="required">*</span>全压',['class'=>'input-group-addon'])
?>
<?=
$form
->field($model, 'power')
->textInput(['type'=>'text'])
->label('<span class="required">*</span>功率',['class'=>'input-group-addon'])
?>
<?=
$form
->field($model, 'orders')
->textInput(['maxlength' => 5,'type'=>'text'])
->label('<span class="required">*</span>排序',['class'=>'input-group-addon'])
?>
<?=
$form
->field($model, 'status')
->radioList(['1'=>'在线', '0'=>'离线'])
->label('<span class="required">*</span>状态')
?>
<?= $form->field($model, 'rememberMe')->checkbox([
'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>",
]) ?>
</div>
<div class="col-lg-12 submit">
<div class="col-lg-3"></div>
<div class="col-lg-8"><button type="submit" class="btn btn-success push-action"><?=$template['action']?></button></div>
</div>
//<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
<?php ActiveForm::end();?>
</div>
</div>
<!--<script>-->
<?php $this->beginBlock('script') ?>
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['script'], \yii\web\View::POS_END); ?>
本文地址:https://blog.csdn.net/weixin_44432032/article/details/111058969