ActiveDataProvider与GridView::wid
2017-06-01 本文已影响0人
IT_min
//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,
]);
},
],
],
])