tp5对数组使用paginate进行分页

2021-08-12
$param = \think\Request::instance()->param();

$data = [
    ['id' => 1, 'name' => '11'],
    ['id' => 2, 'name' => '22'],
    ['id' => 3, 'name' => '33'],
];

$limit = 10;
$count = count($datas);
$page  = $param['page'] ? (int)$param['page'] : 1;
$data  = array_slice($datas, $limit * ($page - 1), $limit);

$config = \think\Config::get('paginate');
$class  = '\\think\\paginator\\driver\\' . ucwords($config['type']);

// 切换页码时带着查询参数
$config['query'] = $param;
// call_user_func([$class, 'getCurrentPath']) 页可以使用此方法自动获取页面地址
$config['path']  = '/admin/dmanage/report.html';

$list = $class::make($data, $limit, $page, $count, false, $config);
$pageObj = $list->render();

 

{/if}