thinkPHP5 数组分页

 thinkPHP5 数组分页,伪分页,只是前端分页,SQL查询不分页

//控制器
$param = $this->request->param();

        if ($param['flag'] == 'show') {
            $res = $this->StatisticsGoodsshareService->getLists($param);
            $list = $res['new_data'];
        } else {
            $list = [];
        }

        //处理分页
        $query = array();

        // if (input("post.CheckTime")) { //条件查询
        //     $query = ['CheckTime' => input("post.CheckTime")];
        // } elseif (input("get.CheckTime")) { //分页查询
        //     $query = ['CheckTime' => input("get.CheckTime")];
        // } else { //初始或者无条件的按钮操作
        // }

        $query = ['CheckTime' => input("get.CheckTime")];


        $data = $list;   //需要输出的数组

        $curpage = $param['page'] ? $param['page'] : 1; //当前第x页,有效值为:1,2,3,4,5...

        $listRow = 15; //每页15行记录

        $dataTo = array();

        $dataTo = array_chunk($data, $listRow);

        $showdata = array();

        if ($dataTo) {
            $showdata = $dataTo[$curpage - 1];
        } else {
            $showdata = null;
        }

        $p = Bootstrap::make($showdata, $listRow, $curpage, count($data), false, [
            'var_page' => 'page',
            'path'     => '', //这里根据需要修改url
            'query'    => $query,
            'fragment' => '',
        ]);


        $server_data  = explode('&', $_SERVER['QUERY_STRING']);
        $params = array();

        foreach ($server_data as $param) {
            list($name, $value) = explode('=', $param, 2);
            $params[urldecode($name)] = urldecode($value);
        }

        $p->appends($params);

        $this->assign('list', $p);

        return $this->fetch('index');


//前端页面
<div class="am-u-lg-12 am-cf">
                            <div class="am-fr"><?= $list->render() ?> </div>
                            <div class="am-fr pagination-total am-margin-right">
                                <div class="am-vertical-align-middle">总记录:<?= $list->total() ?></div>
                            </div>
                        </div>

 

上一篇:基于Thinkphp5框架的易支付网站源码(完整可运行)


下一篇:28.ThinkPhP5 视频教程(三十讲):浅析session、cookie机制