[php]代码库
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Suppliers\Model;
class JsonPage{
public $firstRow; // 起始行数
public $listRows; // 列表每页显示行数
public $parameter; // 分页跳转时要带的参数
public $totalRows; // 总行数
public $totalPages; // 分页总页面数
public $rollPage = 5;// 分页栏每页显示的页数
public $lastSuffix = true; // 最后一页是否显示总页数
private $page = 'page'; //分页参数名
private $nowPage = 1;
// 分页显示定制
private $config = array(
'header' => '%TOTAL_ROW%',
'prev' => '<<',
'next' => '>>',
'first' => '1...',
'last' => '...%TOTAL_PAGE%',
'theme' => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%',
);
/**
* 架构函数
* @param array $totalRows 总的记录数
* @param array $listRows 每页显示记录数
* @param array $parameter 分页跳转的参数
*/
public function __construct($totalRows, $listRows=20, $parameter = array()) {
/* 基础设置 */
$this->totalRows = $totalRows; //设置总记录数
$this->listRows = $listRows; //设置每页显示行数
$pa=I($this->page);
$this->nowPage = empty($pa)?1:intval($pa);
$this->nowPage = $this->nowPage>0 ? $this->nowPage : 1;
$this->firstRow = $this->listRows * ($this->nowPage - 1);
}
/**
* 组装分页链接
* @return string
*/
public function show() {
if(0 == $this->totalRows) return '';
/* 计算分页信息 */
$this->totalPages = ceil($this->totalRows / $this->listRows); //总页数
if(!empty($this->totalPages) && $this->nowPage > $this->totalPages) {
$this->nowPage = $this->totalPages;
}
/* 计算分页零时变量 */
$now_cool_page = $this->rollPage/2;
$now_cool_page_ceil = ceil($now_cool_page);
$this->lastSuffix = $this->totalPages;
//上一页
$data=array();
$data['Prev'] = $this->nowPage - 1;
if($data['Prev']<=0){
$data['Prev']=1;
}
//当前页
$data['Current']=$this->nowPage;
//总行数
$data['TotalRows']=$this->totalRows;
//总页数
$data['TotalPages']=$this->totalPages;
//下一页
$data['Next'] = $this->nowPage + 1;
//第一页
$the_first = '';
if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){
$data['First']=1;
}
//最后一页
$the_end = '';
if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){
$data['Last']=$this->totalPages;
}
//数字连接
if($this->totalPages<$this->rollPage){
$this->rollPage=$this->totalPages;
}
$link_page = "";
for($i = 1; $i <= $this->rollPage; $i++){
if(($this->nowPage - $now_cool_page) <= 0 ){
$page = $i;
}elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){
$page = $this->totalPages - $this->rollPage + $i;
}else{
$page = $this->nowPage - $now_cool_page_ceil + $i;
}
$data['PageSection'][]=$page;
}
//替换分页内容
return $data;
}
}
//调用
$Smartcg_dh=M('smartcg_dh');
$count = $Smartcg_dh->field('id')->where($wheres)->count();
$Page = new \Suppliers\Model\JsonPage($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
$show = $Page->show();// 分页显示输出
初级程序员
by: 梦泪 发表于:2019-06-05 15:47:39 顶(0) | 踩(0) 回复
回复评论