码迷,mamicode.com
首页 > 其他好文 > 详细

分页功能

时间:2021-05-24 16:31:36      阅读:0      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!