You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.4 KiB
86 lines
3.4 KiB
<?php
|
|
|
|
//include_once(dirname(dirname(__FILE__))."/publicBase.php");
|
|
class Page extends publicBase {
|
|
public $totalnum; // 总记录数[必填],例:$page->setTotalnum(100);
|
|
public $page; // 当前页码[必填]
|
|
public $url; // 分页URL[必填]
|
|
public $pagesize=100; // 每页记录数
|
|
|
|
public $viewpagenum=7; // 每页看到的页码数
|
|
public $virtualpage='...'; // 省略或跨越页码
|
|
|
|
public $totalpage;
|
|
|
|
//mysql表中数据量过多时采用的分页改造
|
|
public $first_page_url; //点击”首页“跳转链接
|
|
public $end_page_url; //点击”尾页“跳转链接
|
|
public $prev_page_url; //点击”上一页“跳转链接
|
|
public $next_page_url; //点击”下一页“跳转链接
|
|
public $endpage=false; //跳转到尾页标识
|
|
public $jump_to_page_url; //跳转到某一页链接
|
|
public $maxid; //点击上一页时 当前页面最大id
|
|
public $minid; //点击下一页时 当前页面最小id
|
|
|
|
|
|
/*
|
|
* $pageobj = new Page();
|
|
$pageobj->setTotalnum($totalnum);
|
|
$pageobj->setPage($page);
|
|
$pageobj->setPagesize($pagesize);
|
|
$pageobj->setUrl('/comment/black/page/');
|
|
$plist = $pageobj->getPageList();
|
|
*/
|
|
|
|
/*
|
|
listnum 显示页码数, 默认展示7页
|
|
*/
|
|
public function getPageList() {
|
|
$pagelist = array(); // 构造的翻页数据
|
|
$begin = $last = array(); // 开始,结尾数据
|
|
|
|
$totalpage = ceil($this->totalnum/$this->pagesize); // 总页数
|
|
$this->totalpage = $totalpage;
|
|
$middle_page = ceil($this->viewpagenum/2); // 每页中间页码值
|
|
|
|
if($this->page > $middle_page && $totalpage > $this->viewpagenum) { // 开头有...时
|
|
$begin[] = array('page' => 1, 'url' => $this->url . '1');
|
|
$begin[] = array('page' => $this->virtualpage, 'url' => '');
|
|
$firstpage = $totalpage-$this->viewpagenum+2;
|
|
$endpage = $totalpage;
|
|
|
|
if($totalpage-$this->page > $middle_page) { // 结尾也有...时
|
|
$last[$totalpage-1] = array('page' => $this->virtualpage, 'url'=>'');
|
|
$last[$totalpage] = array('page' => $totalpage, 'url' => $this->url . $totalpage);
|
|
$firstpage = $this->page-$middle_page+2;
|
|
$endpage = $this->page+$middle_page-2;
|
|
}
|
|
} elseif($totalpage-$this->page > $middle_page && $totalpage > $this->viewpagenum) { // 只有结尾的...时
|
|
$last[$totalpage-1] = array('page' => $this->virtualpage, 'url' => '');
|
|
$last[$totalpage] = array('page' => $totalpage, 'url' => $this->url . $totalpage);
|
|
|
|
$firstpage = 1;
|
|
$endpage = $this->viewpagenum-1;
|
|
} else { // 没有...时
|
|
$firstpage = 1;
|
|
$endpage = $totalpage;
|
|
}
|
|
|
|
// 中间页码数据
|
|
for ($i=$firstpage; $i<=$endpage; $i++) {
|
|
$pagelist[$i-1]['page'] = $i;
|
|
$pagelist[$i-1]['url'] = $this->url . $i;
|
|
}
|
|
|
|
return $begin + $pagelist + $last;
|
|
}
|
|
|
|
public function getLimitInfo() {
|
|
$this->first_page_url = $this->url."/page/1"; //首页链接
|
|
$this->end_page_url = $this->url."/end_page/1"; //尾页链接
|
|
$this->jump_to_page_url = $this->url."/jump_to_page"; //跳转到某一页
|
|
if($this->totalnum>0) $this->page = ceil($this->totalnum/$this->pagesize);
|
|
if ($this->page > 1 || $this->endpage) $this->prev_page_url = $this->url.'/page/'.($this->page-1).'/maxid/'.$this->maxid; //上一页连接
|
|
if (!$this->endpage) $this->next_page_url = $this->url.'/page/'.($this->page+1).'/minid/'.$this->minid; //下一页连接
|
|
}
|
|
}
|
|
|