yii中form组件的创建

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); ?>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

原克技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值