首页 > 其他 > 详细

yii2 实现分页

时间:2019-03-09 21:22:22      阅读:152      评论:0      收藏:0      [点我收藏+]

// Controller

public function actionList() {
        $this->layout = ‘right‘;
        $article = new Article();
        $query = $article::find();
        $count = $query->count();

  // 每页显示的数量(可在配置文件中定义)
        $pageSize = 4;

  // 实例分页类冰传入数据总条数和每页显示的数量
        $page = new Pagination([‘totalCount‘ => $count, ‘pageSize‘ =>$pageSize]);

  // 设置offset和limit
        $models = $query->offset($page->offset)->limit($page->limit)->all();
        return $this->render(‘arc_list‘, [
            ‘page‘ => $page,
            ‘models‘ => $models
        ]);
    }

// View

<?php
        foreach ($models as $key => $value) {
            echo ‘...‘;
        }
        ?>

        <?= \yii\widgets\LinkPager::widget([
            ‘pagination‘ => $page,
            ‘firstPageLabel‘ => ‘首页‘,
            ‘prevPageLabel‘ => ‘上一页‘,
            ‘nextPageLabel‘ => ‘下一页‘,
            ‘lastPageLabel‘ => ‘尾页‘,
            ‘maxButtonCount‘ => 1,  // 最大按钮显示条数
            ‘optinons‘ => [‘class‘ => ‘my style‘]   // 自定义分页样式
            ]);
?>

yii2 实现分页

原文:https://www.cnblogs.com/AI-geek/p/10502853.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!