zoukankan      html  css  js  c++  java
  • YII2,gradview使用实例

    1.view模版中使用

      GridView::widget([
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                ['class' => 'yiigridSerialColumn'],
    
                'id',
                ['attribute'=>'title','headerOptions' => ['width' => '250'],],
                'url:url',
                
                [
                    'attribute'=>'type',
                    'value' => function ($data) {
                        return '';
                    },
                    'filter' => '',//是否添加过滤器(本字段的搜索框)
                ],
                [
                    'attribute'=>'status',
                    'value' => function ($data) {
                        return $data->status?'正常':'不正常';
                    },
                    'filter' => '',
                ],
                [
                   'attribute'=>'created',
                       'value'=>function(){
                            return Yii::$app->user->identity->username;
                        },
                        'filter'=>'',
                ],
                 'ctime':datetime',
    
                ['class' => 'yiigridActionColumn','header' => '操作','template'=>'{update} {delete}'],
            ],
        ]);

    2.controller中

            $searchModel = new PostSearch;
            $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams());
            return $this->render('index', [
                'dataProvider' => $dataProvider,
                'searchModel' => $searchModel,
            ]);

    3.model中

        public function search($params)
        {
            $query = Post::find();
            //$query->joinWith(['user']); // 添加关联条件
            $dataProvider = new ActiveDataProvider([
                'query' => $query,
                'sort'=>['defaultOrder'=>['ctime' => SORT_DESC]]
            ]);
            if (!($this->load($params) && $this->validate())) {
                return $dataProvider;
            }
    
            $query->andFilterWhere([
                'id' => $this->id,
                [...]
            ]);
    
            $query->andFilterWhere(['like', 'title', $this->title])->[...];
    
            return $dataProvider;
        }
  • 相关阅读:
    redis集群规范
    mongodb的基本使用
    redis进阶
    redis基本使用
    selenium的基本使用
    C++入门
    C语言入门
    MATLAB中矩阵reshape的顺序规律
    Tensorflow:ImportError: DLL load failed: 找不到指定的模块 Failed to load the native TensorFlow runtime
    差分定位和精密定位
  • 原文地址:https://www.cnblogs.com/benlightning/p/4386524.html
Copyright © 2011-2022 走看看