位置: Thinkphp/Library/Think/Pages 或Page

pages.class.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 Think; class Pages{
public $firstRow; // 起始行数
public $listRows; // 列表每页显示行数
public $parameter; // 分页跳转时要带的参数
public $totalRows; // 总行数
public $totalPages; // 分页总页面数
public $rollPage = 11;// 分页栏每页显示的页数
public $lastSuffix = true; // 最后一页是否显示总页数 private $p = 'p'; //分页参数名
private $url = ''; //当前链接URL
private $nowPage = 1; // 分页显示定制
private $config = array(
'header' => '<span class="rows">共 %TOTAL_ROW% 条记录</span>',
'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()) {
C('VAR_PAGE') && $this->p = C('VAR_PAGE'); //设置分页参数名称
/* 基础设置 */
$this->totalRows = $totalRows; //设置总记录数
$this->listRows = $listRows; //设置每页显示行数
$this->parameter = empty($parameter) ? $_GET : $parameter;
$this->nowPage = empty($_GET[$this->p]) ? 1 : intval($_GET[$this->p]);
$this->nowPage = $this->nowPage>0 ? $this->nowPage : 1;
$this->firstRow = $this->listRows * ($this->nowPage - 1);
} /**
* 定制分页链接设置
* @param string $name 设置名称
* @param string $value 设置值
*/
public function setConfig($name,$value) {
if(isset($this->config[$name])) {
$this->config[$name] = $value;
}
} /**
* 生成链接URL
* @param integer $page 页码
* @return string
*/
private function url($page){
return str_replace(urlencode('[PAGE]'), $page, $this->url);
} /**
* 组装分页链接
* @return string
*/
public function show() {
if(0 == $this->totalRows) return ''; /* 生成URL */
$this->parameter[$this->p] = '[PAGE]';
$this->url = U(ACTION_NAME, $this->parameter);
/* 计算分页信息 */
$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->config['last'] = $this->totalPages; //上一页
$up_row = $this->nowPage - 1;
$up_page = $up_row > 0 ? '<a class="prev" href="' . $this->url($up_row) . '">' . $this->config['prev'] . '</a>' : ''; //下一页
$down_row = $this->nowPage + 1;
$down_page = ($down_row <= $this->totalPages) ? '<a class="next" href="' . $this->url($down_row) . '">' . $this->config['next'] . '</a>' : ''; //第一页
$the_first = '';
if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){
$the_first = '<a class="first" href="' . $this->url(1) . '">' . $this->config['first'] . '</a>';
} //最后一页
$the_end = '';
if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){
$the_end = '<a class="end" href="' . $this->url($this->totalPages) . '">' . $this->config['last'] . '</a>';
} //数字连接
$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;
}
if($page > 0 && $page != $this->nowPage){ if($page <= $this->totalPages){
$link_page .= '<a class="num" href="' . $this->url($page) . '">' . $page . '</a>';
}else{
break;
}
}else{
if($page > 0 && $this->totalPages != 1){
$link_page .= '<span class="current">' . $page . '</span>';
}
}
} //替换分页内容
$page_str = str_replace(
array('%HEADER%', '%NOW_PAGE%', '%UP_PAGE%', '%DOWN_PAGE%', '%FIRST%', '%LINK_PAGE%', '%END%', '%TOTAL_ROW%', '%TOTAL_PAGE%'),
array($this->config['header'], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages),
$this->config['theme']);
return "<div>{$page_str}</div>";
}
}

  

thinkphp 分页Pages的更多相关文章

  1. thinkphp分页实现

    以上为我对于thinkphp分页的实现效果,两种方法,一种调用公共函数中的函数方法(参考http://www.cnblogs.com/tianguook/p/4326613.html),一种是在模型中 ...

  2. ThinkPHP 分页功能梳理

    最近在开发一个项目,使用了国内流行的ThinkPHP框架,我之前没怎么用过这个框架,也是临时抱佛脚,用的不怎么样?可能理解不是很深刻,如果有说的不对或不正确的地方,请大家多包涵,多指教. ThinkP ...

  3. ThinkPHP分页使用例子(二十一)

    原文:ThinkPHP分页使用例子(二十一) ThinkPHP分页使用 PHP代码: public function fenye(){ $User = M('Leyangjun'); // 实例化Us ...

  4. ThinkPHP分页实例

    ThinkPHP分页实例 (2014-09-20 15:34:36)   很多人初学thinkphp时,不太熟悉thinkphp的分页使用方法,现在将自己整理的分页方法分享下,有需要的朋友可以看看. ...

  5. thinkphp 分页类 url 编码处理

    在做thinkphp分页的时候  thinkphp 中的分页 有一个小问题 就是 在有form 表单 搜索中文的时候,点击下一页的话 中文会被转换成编码. 如图: 最直接的方法就是 直接修改 thin ...

  6. thinkphp分页

    thinkphp默认分页 html代码 <div class="f_r"> {$page} </div> 一:最简单的分页 $m = M('stock_lo ...

  7. thinkphp分页格式的完全自定义,直接输入数字go到输入数字页

    实现分页效果如下: 以下标注红色字体的为重点   找到文件page.class.php在ThinkPHP/Library/Thinkpage.class.php并打开文件,复制函数show,在本文件中 ...

  8. thinkphp分页二,分装到funciton.php

    function.php代码 <?php /* 全局分页 * $table 数据表名 * $order 排序 * $pagesize 每页显示N个 * $where 查询条件 * $rollPp ...

  9. thinkphp分页样式

    html代码: <div class="pages">{$page}</div> css代码: .pages{ width:100.5%; text-ali ...

随机推荐

  1. ASP.Net MVC OA项目笔记<一>

    1.1.1 新建空白解决方案CZBK.ItcastOA 1.2.1 添加类库 1.2.2 同上添加多个类库 生成的 class1.cs先不用删除,删了的后,后面可能没办法直接点引用 1.3.1 添加表 ...

  2. UWP Button添加圆角阴影(三)

    原文:UWP Button添加圆角阴影(三) Composition DropShadow是CompositionAPI中的东西,使用Storyboard设置某个属性,就是频繁的触发put_xxx() ...

  3. Android TV 开发(5)

    本文来自网易云社区 作者:孙有军 问题3:TV launcher中没有入口图标 如果需要出现入口图标,你必须要在AndroidManifest中配置action为android.intent.acti ...

  4. idea 映射文件同class文件一起打包安装

    经过几天的摸索,已经能够用idea做日常的Demo了,在复习的过程中,又在学的知识,所以进度有点慢,但自己好像有点着急,为自己的效率 但是自己也是知道的,只顾速度,最后的学完的效果也不是自己想要的,所 ...

  5. solr 5.5使用 和pyg里 的4.10.3版 部署到tomcat中不一样(不使用内置jetty)

    http://www.cnblogs.com/zhuxiaojie/p/5764680.html

  6. jzoj4223

    考慮這樣一種暴力:將所有<=x的邊按照類似最小生成樹的方式加入答案,然後用下面的方法統計答案: 1.首先加入一條邊 2.看這條邊是否將會合成聯通塊,如果會,那麼加進這條邊,記這條邊一端聯通塊大小 ...

  7. react中组件的渲染

    1.封装props对象 2.调用组件函数,得到返回的react元素 3.ReactDom把React元素转成真实的DOM元素并且插入到目标容器内部

  8. git add .添加不成功

    情景: 我首先在一个有许多文件的文件夹中  git init  创建一个git管理仓库 之后 git add . 之后 git commit -m "提交" 发现提交不成功,文件没 ...

  9. Spring Boot log4j多环境日志级别的控制

    之前介绍了在<Spring boot中使用log4j>,仅通过log4j.properties对日志级别进行控制,对于需要多环境部署的环境不是很方便,可能我们在开发环境大部分模块需要采用D ...

  10. Go语言学习笔记(1)——Hello World!

    第一个go程序——HelloWorld.go 源码 : package main import ("fmt") // import "fmt" func mai ...