ActiveDataProvider与GridView::widge的使用

//ActiveDataProvider与GridView::widge的使用

public function actionTopic()
    {
        $dataProvider = new ActiveDataProvider([
            'query' => Topic::find()
                    ->where('end_time >=' . $_SERVER['REQUEST_TIME'])
                    ->andWhere('start_time <=' . $_SERVER['REQUEST_TIME'])
                    ->orderBy(['topic_id' => SORT_DESC]),
        ]);
        return $this->render('topic', [
                    'dataProvider' => $dataProvider,
        ]);
    }
view/goods/topic.php
GridView::widget([
    'dataProvider' => $dataProvider,
    'filterPosition' => false, //关闭Yii默认搜索栏
    'layout' => "{items}{summary}{pager}",
    'summary' => '共{totalCount}个记录,每页{count},共{pageCount}页',
    'columns' => [
        'topic_id',
        'title',
        'start_time:datetime',
        [
            'attribute' => '二维码',
            'format' => 'raw',
            'value' => function ($data)
            {
                return Html::a('二维码', '#', [
                            'data-toggle' => 'modal',
                            'data-target' => '#myModal',
                            'class' => 'btn btn-primary topic_ids',
                            'id' => $data->topic_id,
                ]);
            },
                ],
            ],
        ])

你可能感兴趣的:(ActiveDataProvider与GridView::widge的使用)