@H_
404_0@废话不多说先上图预览下,即本
博客的
分页;@H_
404_0@

@H_
404_0@这个
分页类是在think
PHP框架内置的
分页类的基础上
修改而来,原
分页类的一些设计,在实际运用中感觉不是很方便;@H_
404_0@1:只有一页
内容时
不显示分页;@H_
404_0@2:原
分页类在当前页是第一页和最后一页的时候,
不显示第一页和最后一页的按钮;@H_
404_0@

@H_
404_0@3:
分页数比较少时
不显示首页和末页按钮;@H_
404_0@4:包裹
分页内容的父级div没有class;@H_
404_0@
针对以上问题逐一进行了修改成如下;@H_
404_0@1:如果没有数据
不显示分页,如果有一页及以上
内容即
显示分页;@H_
404_0@2:
默认就
显示第一页和最后一页按钮,但是在当前页是第一页和最后一页的时候按钮点击无
效果;@H_
404_0@3:
默认就
显示首页和末页按钮;@H_
404_0@4:为包裹
分页内容的父级div
添加名为page的class;@H_
404_0@5:
显示总共查出的
内容条数;@H_
404_0@
示例环境:think
PHP3.2.3@H_
404_0@
分页类目录:/Think
PHP/Library/Org/Bjy/Page.class.
PHP@H_
404_0@
分页类
代码如下:@H_
404_0@<?
PHP@H_
404_0@// +----------------------------------------------------------------------@H_
404_0@// | Think
PHP [ WE CAN DO IT JUST THINK IT ]@H_
404_0@// +----------------------------------------------------------------------@H_
404_0@// |
copyright (c) 2006-2014 http://think
PHP.cn All rights reserved.@H_
404_0@// +----------------------------------------------------------------------@H_
404_0@// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )@H_
404_0@// +----------------------------------------------------------------------@H_
404_0@// | Author: 麦当苗儿 <
[email protected]> <http://www.zjzit.cn>@H_
404_0@// +----------------------------------------------------------------------@H_
404_0@/*@H_
404_0@ *
PHP分页类@H_
404_0@ *
修改者:白俊遥@H_
404_0@ * 日 期:2015.5.10@H_
404_0@ * 邮 箱:
[email protected]@H_
404_0@ * 博 客:http://www.baijunyao.com@H_
404_0@ */@H_
404_0@namespace OrgBjy;@H_
404_0@ @H_
404_0@class Page{@H_
404_0@ public $f
irstRow; // 起始行数@H_
404_0@ public $listRows; // 列表每页
显示行数@H_
404_0@ public $p
arameter; //
分页跳转时要带的参数@H_
404_0@ public $totalRows; // 总行数@H_
404_0@ public $totalPages; //
分页总
页面数@H_
404_0@ public $rollPage = 5;//
分页栏每页
显示的页数@H_
404_0@ public $lastSuffix = true; // 最后一页是否
显示总页数@H_
404_0@ @H_
404_0@ private $p = 'p'; //
分页参数名@H_
404_0@ private $url = ''; //当前
链接URL@H_
404_0@ private $
NowPage = 1;@H_
404_0@ @H_
404_0@ //
分页显示定制@H_
404_0@ private $con
fig = array(@H_
404_0@ 'header' => '<span class="rows">共 %TOTAL_ROW% 条记录</span>',@H_
404_0@ 'f
irst' => '
首页',@H_
404_0@ 'prev' => '
上一页',@H_
404_0@ 'next' => '
下一页',@H_
404_0@ 'last' => '末页',@H_
404_0@ 'theme' => '%F
irsT% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%',@H_
404_0@ );@H_
404_0@ @H_
404_0@ /**@H_
404_0@ * 架构
函数@H_
404_0@ * @p
aram array $totalRows 总的记录数@H_
404_0@ * @p
aram array $listRows 每页
显示记录数@H_
404_0@ * @p
aram array $p
arameter
分页跳转的参数@H_
404_0@ */@H_
404_0@ public function __construct($totalRows,$listRows=20,$p
arameter = array()) {@H_
404_0@ C('VAR_PAGE') && $this->p = C('VAR_PAGE'); //设置
分页参数
名称@H_
404_0@ /* 基础设置 */@H_
404_0@ $this->totalRows = $totalRows; //设置总记录数@H_
404_0@ $this->listRows = $listRows; //设置每页
显示行数@H_
404_0@ $this->p
arameter = empty($p
arameter) ? $_GET : $p
arameter;@H_
404_0@ $this->
NowPage = empty($_GET[$this->p]) ? 1 : intval($_GET[$this->p]);@H_
404_0@ $this->
NowPage = $this->
NowPage>0 ? $this->
NowPage : 1;@H_
404_0@ $this->f
irstRow = $this->listRows * ($this->
NowPage - 1);@H_
404_0@ }@H_
404_0@ @H_
404_0@ /**@H_
404_0@ * 定制
分页链接设置@H_
404_0@ * @p
aram string $name 设置
名称@H_
404_0@ * @p
aram string $value 设置值@H_
404_0@ */@H_
404_0@ public function setCon
fig($name,$value) {@H_
404_0@ if(isset($this->con
fig[$name])) {@H_
404_0@ $this->con
fig[$name] = $value;@H_
404_0@ }@H_
404_0@ }@H_
404_0@ @H_
404_0@ /**@H_
404_0@ *
生成链接URL@H_
404_0@ * @p
aram integer $page
页码@H_
404_0@ * @return string@H_
404_0@ */@H_
404_0@ private function url($page){@H_
404_0@ return str_replace(urlencode('[PAGE]'),$page,$this->url);@H_
404_0@ }@H_
404_0@ @H_
404_0@ /**@H_
404_0@ * 组装
分页链接@H_
404_0@ * @return string@H_
404_0@ */@H_
404_0@ public function show() {@H_
404_0@ if(0 == $this->totalRows) return '';@H_
404_0@ @H_
404_0@ /*
生成URL */@H_
404_0@ $this->p
arameter[$this->p] = '[PAGE]';@H_
404_0@ $this->url = U(ACTION_NAME,$this->p
arameter);@H_
404_0@ /* 计算
分页信息 */@H_
404_0@ $this->totalPages = ceil($this->totalRows / $this->listRows); //总页数@H_
404_0@ if(!empty($this->totalPages) && $this->
NowPage > $this->totalPages) {@H_
404_0@ $this->
NowPage = $this->totalPages;@H_
404_0@ }@H_
404_0@ @H_
404_0@ /* 计算
分页零时变量 */@H_
404_0@ $
Now_cool_page = $this->rollPage/2;@H_
404_0@ $
Now_cool_page_ceil = ceil($
Now_cool_page);@H_
404_0@ @H_
404_0@ //
上一页@H_
404_0@ $up_row = $this->
NowPage - 1;@H_
404_0@ $up_page = $up_row > 0 ? '<a class="prev" href="' . $this->url($up_row) . '">' . $this->con
fig['prev'] . '</a>' : '<a class="prev" href="javascript:;">' . $this->con
fig['prev'] . '</a>';@H_
404_0@ @H_
404_0@ //
下一页@H_
404_0@ $down_row = $this->
NowPage + 1;@H_
404_0@ $down_page = ($down_row <= $this->totalPages) ? '<a class="next" href="' . $this->url($down_row) . '">' . $this->con
fig['next'] . '</a>' : '<a class="next" href="javascript:;">' . $this->con
fig['next'] . '</a>';@H_
404_0@ @H_
404_0@ //第一页@H_
404_0@ $the_f
irst = '<a class="f
irst" href="' . $this->url(1) . '">' . $this->con
fig['f
irst'] . '</a>';@H_
404_0@ @H_
404_0@ //最后一页@H_
404_0@ $the_end = '<a class="end" href="' . $this->url($this->totalPages) . '">' . $this->con
fig['last'] . '</a>';@H_
404_0@ @H_
404_0@ //数字连接@H_
404_0@ $link_page = "";@H_
404_0@ for($i = 1; $i <= $this->rollPage; $i++){@H_
404_0@ if(($this->
NowPage - $
Now_cool_page) <= 0 ){@H_
404_0@ $page = $i;@H_
404_0@ }elseif(($this->
NowPage + $
Now_cool_page - 1) >= $this->totalPages){@H_
404_0@ $page = $this->totalPages - $this->rollPage + $i;@H_
404_0@ }else{@H_
404_0@ $page = $this->
NowPage - $
Now_cool_page_ceil + $i;@H_
404_0@ }@H_
404_0@ if ($page>0) {@H_
404_0@ if($page != $this->
NowPage){@H_
404_0@ if($page <= $this->totalPages){@H_
404_0@ $link_page .= '<a class="num" href="' . $this->url($page) . '">' . $page . '</a>';@H_
404_0@ }else{@H_
404_0@ break;@H_
404_0@ }@H_
404_0@ }else{@H_
404_0@ $link_page .= '<span class="current">' . $page . '</span>';@H_
404_0@ } @H_
404_0@ }@H_
404_0@ @H_
404_0@ }@H_
404_0@ @H_
404_0@ //替换
分页内容@H_
404_0@ $page_str = str_replace(@H_
404_0@ array('%HEADER%','%
Now_PAGE%','%UP_PAGE%','%DOWN_PAGE%','%F
irsT%','%LINK_PAGE%','%END%','%TOTAL_ROW%','%TOTAL_PAGE%'),@H_
404_0@ array($this->con
fig['header'],$this->
NowPage,$up_page,$down_page,$the_f
irst,$link_page,$the_end,$this->totalRows,$this->totalPages),@H_
404_0@ $this->con
fig['theme']);@H_
404_0@ return '<div class="page">'.$page_str.'</div>';@H_
404_0@ }@H_
404_0@}@H_
404_0@
分页类调用:@H_
404_0@ $count=$this->where($where)->count();@H_
404_0@ $page=new OrgBjyPage($count,$limit);@H_
404_0@ $list=$this->where($where)->order('addtime desc')->limit($page->f
irstRow.','.$page->listRows)->select();@H_
404_0@ $show=$page->show();@H_
404_0@
分页类css:@H_
404[email protected] {@H_
404_0@ background:#fff;@H_
404_0@
Box-shadow:0 1px 2px 0 #e2e2e2@H_
404_0@}@H_
404[email protected] .page {@H_
404_0@ width:100%;@H_
404_0@ padding:30px 15px;@H_
404_0@ background:#fff;@H_
404_0@ text-align:center;@H_
404_0@ overflow:hidden@H_
404_0@}@H_
404[email protected] .page .f
irst,.b-page .page .prev,.b-page .page .current,.b-page .page .num,.b-page .page .next,.b-page .page .end {@H_
404_0@ padding:8px 16px;@H_
404_0@ margin:0 5px;@H_
404_0@
display:inline-block;@H_
404_0@ color:#008cba;@H_
404_0@ border:1px solid #f2f2f2;@H_
404_0@ border-radius:5px@H_
404_0@}@H_
404[email protected] .page .f
irst:hover,.b-page .page .prev:hover,.b-page .page .current:hover,.b-page .page .num:hover,.b-page .page .next:hover,.b-page .page .end:hover {@H_
404_0@ text-
decoration:none;@H_
404_0@ background:#f8f5f5@H_
404_0@}@H_
404[email protected] .page .current {@H_
404_0@ background-color:#008cba;@H_
404_0@ color:#fff;@H_
404_0@ border-radius:5px;@H_
404_0@ border:1px solid #008cba@H_
404_0@}@H_
404[email protected] .page .current:hover {@H_
404_0@ text-
decoration:none;@H_
404_0@ background:#008cba@H_
404_0@}@H_
404_0@
分页类的使用
方法和原think
PHP相同,具体参考:think
PHP手册-数据
分页
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。