thinkphp5的paginator實現陣列的分頁查詢
阿新 • • 發佈:2018-12-26
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>