Sanlence

Sanlence

这家伙有点懒,还没写个性签名!

  • 财富值115
  • 威望值0
  • 总积分165

个人信息

  • 写这么清楚还是没有人回答?

  • 这个是EquipmentArchives类的代码:

    <?php
    
    namespace app\models;
    
    
    use yii\db\ActiveRecord;
    use yii\helpers\HtmlPurifier;
    
    /**
     * This is the model class for table "ledger".
     *
     * @property string $id
     * @property integer $eid
     * @property string $city
     * @property string $entname
     * @property string $ent_type
     * @property string $name
     * @property string $type
     * @property string $io
     * @property string $model
     * @property string $_level
     * @property string $_range
     * @property string $vendor
     * @property string $serial
     * @property string $managenum
     * @property string $place
     * @property string $note
     * @property string $rec_time
     * @property string $status_time
     * @property string $jdtime
     * @property integer $jdcycle
     */
    class EquipmentArchives extends ActiveRecord
    {
        /**
         * @inheritdoc
         */
        public static function tableName()
        {
            return 'ledger';
        }
    
        /**
         * @inheritdoc
         */
        public function rules()
        {
            return [
                [['eid', 'city', 'entname', 'ent_type', 'name', 'type', 'io', 'model', '_level', '_range', 'vendor', 'serial', 'managenum', 'place', 'rec_time', 'status_time', 'jdtime', 'jdcycle'], 'required'],
                [['eid', 'jdcycle'], 'integer'],
                [['rec_time', 'status_time', 'jdtime'], 'safe'],
                [['city', 'ent_type', 'name', 'type', 'io', 'model', '_level', '_range', 'vendor', 'serial', 'managenum', 'place'], 'string', 'max' => 50],
                [['entname'], 'string', 'max' => 200],
                [['note'], 'string', 'max' => 255],
            ];
        }
    
        /**
         * @inheritdoc
         */
        public function attributeLabels()
        {
            return [
                'id' => '编号',
                'eid' => 'Eid',
                'city' => '所在城市',
                'entname' => '企业名称',
                'ent_type' => '组织规模',
                'name' => '计量器具名称',
                'type' => '器具类别',
                'io' => '输入输出用能',
                'model' => '型号规格',
                '_level' => '准确度等级',
                '_range' => '测量范围',
                'vendor' => '生产厂家',
                'serial' => '出厂编号',
                'managenum' => '用能单位管理编号',
                'place' => '安装使用地点',
                'note' => '备注',
                'rec_time' => '录入时间',
                'status_time' => '状态发生时间',
                'jdtime' => '检定时间',
                'jdcycle' => '检定周期',
            ];
        }
    
        public static function findById($id)
        {
            return static::findOne(['id'=>$id]);
        }
    
        public function add()
        {
            $record = new EquipmentArchives();
    
            $record->eid = HtmlPurifier::process($this->eid);
            $record->city = HtmlPurifier::process($this->city);
            $record->entname = HtmlPurifier::process($this->entname);
            $record->ent_type = HtmlPurifier::process($this->ent_type);
            $record->name = HtmlPurifier::process($this->name);
            $record->type = HtmlPurifier::process($this->type);
            $record->io = HtmlPurifier::process($this->io);
            $record->model = HtmlPurifier::process($this->model);
            $record->_level = HtmlPurifier::process($this->_level);
            $record->_range = HtmlPurifier::process($this->_range);
            $record->vendor = HtmlPurifier::process($this->vendor);
            $record->serial = HtmlPurifier::process($this->serial);
            $record->managenum = HtmlPurifier::process($this->managenum);
            $record->place = HtmlPurifier::process($this->place);
            $record->rec_time = HtmlPurifier::process($this->rec_time);
            $record->status_time = HtmlPurifier::process($this->status_time);
            $record->jdtime = HtmlPurifier::process($this->jdtime);
            $record->jdcycle = HtmlPurifier::process($this->jdcycle);
            $record->note = HtmlPurifier::process($this->note);
    
            return $record->save();
        }
    }
    
  • 回复了 的回答

    当前你贴出的代码没有错误的地方.应该是你views/major文件有错误的地方.可以再检查一下,或者在贴出那边的代码.
    同时,错误提示上应该有错误位置的提示.可以关注下错误位置.

    下面的是major的前端代码

    <?php
    
    $this->title = '主要用能计量器具管理';
    ?>
    
    <form class="form-inline" role="form" method="get" action="<?php echo \yii\helpers\Url::toRoute('equipment-archives/major'); ?>">
        <input type="hidden" name="r" value="equipment-archives/major">
        <div class="form-group">
            <label class="sr-only" for="key">名称</label>
            <input type="text" class="form-control" id="key" name="key" placeholder="请输入查询的关键字">
        </div>
        &ensp;
        <button type="submit" class="btn btn-success glyphicon glyphicon-search">搜索</button>
    </form>
    <br/>
    
    <?php
        \yii\helpers\Html::a('<span class="	glyphicon glyphicon-plus btn btn-success btn-sm">新增</span>', \yii\helpers\Url::toRoute('equipment-archives/add'), ['target' => '_blank']);
    ?>
    
    <?php
    echo \yii\grid\GridView::widget([
        'dataProvider' => $dataProvider,
        // rowOptions可以设置每行的id,class,width,height等,此处设置每行的id,id由拼接而成,$model是会自动获取传递
        // 过来的dataProvider的query中的一个对象(查询结果的每一行,每个对象将在gridview显示一行)。由于ID的唯一性
        // 每行tr的id都是唯一的。
        'rowOptions' => function ($model) {
            return [
                'id' => 'tr-' . $model->id,
            ];
        },
        'columns' => [
            [
                // 此处增加一列复选框
                'class' => 'yii\grid\CheckboxColumn',
                // 对整个checkbox列都设置class=check。
                'cssClass' => 'check',
                // ---------额外的知识----------
                // 1 如果要使得该列不可见,必须设置‘visible’ => false,因为该属性默认是true。
                // 2 如果想设置该列不要排序,可以设置'enableSorting' => false,因为该属性默认为true。
                // 3 header也可以设置列名的名称,比如:'header' => '选中',并且header默认是不排序的。另外,header
                //   支持对html的解析并展示。
                // 4 label是列名的默认形式 -> 默认排序,不支持对html的解析。不管是使用header还是label,都需要指明
                // 对那个属性进行设置:'attribute' => ‘数据库表字段名’。
            ],
            // 这些属性会自动关联到User表,并且展示时会显示每个属性对应的Label。
            'id',
            'name',
            'type',
            'entname',
            'model',
            [
                'attribute' => 'jdtime',
                'header' => '检定状态',
                'value' => function ($model) {
                    return  date('Y-m-d', strtotime("$model->jdtime + $model->jdcycle + 1 year")) > date("Y-m-d", time())? '已检定' : '待检定';
                }
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'template' => '{update} {delete}',
                'buttons' => [
                    'update' => function ($url, $model, $key) {
                        return \yii\helpers\Html::a('<span class="glyphicon glyphicon-pencil btn btn-success btn-xs"></span>', \yii\helpers\Url::toRoute('equipment-archives/update') . "&name={$model->id}", ['target' => '_blank']);
                    },
                    'delete' => function ($url, $model) {
                        return "<button class='btn-delete btn btn-danger btn-xs' data-url='" . YII::$app->urlManager->createUrl(['/equipment-archives/delete', 'id' => $model->id]) . "'><span class='glyphicon glyphicon-trash'></span></button>";
                    },
                ]
            ]
        ],
        // 当没有查询到结果时,显示这条消息
        'emptyText' => '平台还没有创建用户',
        // 当没有查询到结果时,对显示的消息设置css
        'emptyText' => ['style' => 'color:red;font-weight:bold'],
        // 去掉gridview显示在左上方的类似“Showing 1-1 of 2 items.”的内容
        'layout' => "{items}\n{pager}",
        // 如果没有查询到结果,那么整个gridview连表的标题都不会显示。
        'showOnEmpty' => false,
    ]);
    
  • 回复了 的回答

    EquipmentArchives::find()->where(['entname' => $entname])->asarray()->all();符合条件的所有数据列并转为数组
    EquipmentArchives::find()->where(['entname' => $entname])->asarray()->one();符合条件的第一行数据列并转为数组
    EquipmentArchives::find()->where(['entname' => $entname])->all();没有asarray默认取出来的是对象

    你说的这三个解决不了问题的,我是需要分页,后面gridview需要实例化的对象

  • 赞了教程
    Yii2 使用表单上传文件
  • 2017-05-31 已签到
    连续签到1天,获得了5个金钱
  • 2017-04-10 已签到
    连续签到1天,获得了5个金钱
助理 等级规则
165/200
资料完整度
10/100
用户活跃度
0/100

Ta的关注

2

Ta的粉丝

0

Ta的访客

3