二维数组页码分页


$param = $this->request->param();

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

$limit = 3;
$count = count($data);
$page = isset($param['page']) ? isset($param['page']) : 1;
$data = array_slice($data, $limit * ($page - 1), $limit);
$config = [
'type' => 'page\PageBootstrap',
'var_page' => 'page',
'list_rows' => 3,
'query' => $param
];
// $config = \think\Config::get('paginate');
$class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\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();
echo "<pre>";
var_dump($pageObj);die();

posted @ 2023-12-13 10:46  php毛宏历的博客  阅读(8)  评论(0编辑  收藏  举报