标签:col his 检索 数据 alc public rgb 默认分页 orderby
一.GridView
在控制器
public function actionIndex() { $query = User::find(); $pages = new Pagination([‘totalCount‘ =>$query->count()]); $dataProvider = new ActiveDataProvider([ ‘query‘ => $query, ‘pagination‘ => [ ‘pagesize‘ => ‘10‘ ] ]); return $this->render(‘index‘, [ ‘dataProvider‘ => $dataProvider, ‘pages‘ => $pages, ]);
视图中
?= GridView::widget([ //检索数据 ‘dataProvider‘ => $dataProvider, ‘pager‘=>[ //取消Gridview默认分页 // ‘options‘=>[‘class‘=>‘hidden‘], //前后头尾 ‘firstPageLabel‘=>"首页", ‘prevPageLabel‘=>‘上一页‘, ‘nextPageLabel‘=>‘下一页‘, ‘lastPageLabel‘=>‘尾页‘, ],
‘columns‘ => [
//...
]
]);
二.LinkPager设置
控制器中
<?php //other code use yii\data\Pagination; public function actionArticlelist() { //分页读取类别数据 $model = User::find()->with(‘cate‘); $pagination = new Pagination([ ‘defaultPageSize‘ => 3, ‘totalCount‘ => $model->count(), ]); $model = $model->orderBy(‘id ASC‘) ->offset($pagination->offset) ->limit($pagination->limit) ->all(); return $this->render(‘index‘, [ ‘model‘ => $model, ‘pagination‘ => $pagination, ]); } ?>
视图中 若使用了GridView默认分页在其中输入 ‘options‘=>[‘class‘=>‘hidden‘] 取消分页
‘options‘=>[‘class‘=>‘hidden‘],
<?php foreach ($models as $model) { // 在这里显示 $model } // 显示分页 echo LinkPager::widget([ ‘pagination‘ => $pagination, ‘firstPageLabel‘=>"首页", ‘prevPageLabel‘=>‘上一页‘, ‘nextPageLabel‘=>‘下一页‘, ‘lastPageLabel‘=>‘尾页‘, ]); ?>
标签:col his 检索 数据 alc public rgb 默认分页 orderby
原文地址:https://www.cnblogs.com/qingquanqimo/p/14786039.html