thinkphp5的paginator实现数组的分页查询
转
1、控制器
use think\paginator\driver\Bootstrap;
$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 = array(); //需要输出的数组
$curpage = input('page') ? input('page') : 1;//当前第x页,有效值为:1,2,3,4,5...
$listRow = 10;//每页10行记录
$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('url'),//这里根据需要修改url
'query' => $query,
'fragment' => '',
]);
$p->appends($_GET);
$this->assign('plist', $p);
$this->assign('plistpage', $p->render());
return $this->fetch();
2、模版渲染
{foreach name="plist" item="v"}
{$v["id"]}
{/foreach}
<div align="right">
{$plistpage}
</div>