• 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;
        }
  • 相关阅读:
    2. Get the codes from GIT
    1. Install Git and GitExtension
    [Git]Git的常用命令
    测试用例Excel模板For Quality Center
    测试用例excel模板
    如何在win 2008 server和win 7上add web site
    Jmeter运行过程中如何让Fiddler同时可以抓获到服务器的应答报文
    Windows系统文件mshtml.dll
    Jmeter中的XPath Assertion
    AIM Tech Round (Div. 2) B
  • 原文地址:https://www.cnblogs.com/benlightning/p/4386524.html
Copyright © 2020-2023  润新知