<?php

//namespace Component;
/**
* 2016-3-27
* @author ankang
*/
class Page {
private $ShowPage;
private $CountPage;
private $Floorp;
private $PageUrl;
private $PageClass;
private $CurClass; /**
* @author ankang
* @param number $CountNum 数据总数
* @param string $PageUrl 跳转链接
* @param string $PageClass <a>标签 总体样式
* @param string $PageUrl 当前页样式
* @param number $PageSize 每页显示的数据条数
* @param number $ShowPage 每次显示的页数
*/
public function __construct($CountNum, $PageUrl = NULL, $PageClass = NULL,$CurClass = NULL, $PageSize = 20, $ShowPage = 5) {
$this->ShowPage = $ShowPage;
$this->CountPage = ceil ( $CountNum / $PageSize );
$this->Floorp = floor ( $ShowPage / 2 ); // 偏移量
$this->PageClass = is_null ( $PageClass ) ? '' : $PageClass;
$this->CurClass = is_null ( $CurClass ) ? '' : $CurClass; // $ServerURL = ( preg_match('/\?/i', $_SERVER['REQUEST_URI']))?preg_replace('/\&p\=[0-9]+/i', "", $_SERVER['REQUEST_URI']) : $_SERVER['REQUEST_URI']."?";
// if( substr($ButURL,0,2)=='//' ){
// $ServerURL = substr($ServerURL,1);
// }
// $url = preg_replace('/p=[\d]*/i', '', $ServerURL);
$url = '';
//推荐自己传url,不传也可以打开上面的代码自动获取
$this->PageUrl = is_null ( $PageUrl ) ? $url : $PageUrl;
} /**
*
* @param number $Page
* @param string $ShowToPage
* 首页,上下页,尾页
* @param string $Html 标签元素,li,p
* @return string
*/
public function getPage($Page = 1, $ShowToPage = true, $Html = null) {
$StartPage = ($Page - $this->Floorp); // 开始页码
$EndPage = ($Page + $this->Floorp); // 结束页码 if ($this->CountPage < $this->ShowPage) {
$StartPage = 1;
$EndPage = $this->CountPage;
} if ($StartPage < 1) {
$StartPage = 1;
$EndPage = $this->ShowPage;
} if ($EndPage > $this->CountPage) {
$StartPage = $this->CountPage - $this->ShowPage + 1;
$EndPage = $this->CountPage;
} $PageHtml = ''; if (! is_null ( $Html )) {
if ($Html == 'li') {
$Shtml = '<li>';
$Ehtml = '</li>';
} else {
$Shtml = '<p>';
$Ehtml = '</p>';
}
} if (true == $ShowToPage) {
$PageHtml .= "$Shtml<a href='{$this->PageUrl}p=1'>« 首页</a>$Ehtml";
$PrveUrl = $this->getPrve($Page);
$PageHtml .= "$Shtml<a href='{$PrveUrl}'>« 上一页</a>$Ehtml";
} for($i = $StartPage; $i <= $EndPage; $i ++) {
if ($Page == $i) {
$PageHtml .= "$Shtml<a href='{$this->PageUrl}p={$i}' class='{$this->CurClass}'>{$i}</a>$Ehtml";
} else {
$PageHtml .= "$Shtml<a href='{$this->PageUrl}p={$i}' class='{$this->PageClass}'>{$i}</a>$Ehtml";
}
} if (true == $ShowToPage) {
$NextUrl = $this->getNext($Page);
$PageHtml .= "$Shtml<a href='{$NextUrl}'>下一页 »</a>$Ehtml";
$PageHtml .= "$Shtml<a href='{$this->PageUrl}p={$this->CountPage}' >尾页 »</a>$Ehtml";
} return $PageHtml;
} public function getPrve($Page){
if ($Page != 1) {
$Prve = $Page - 1;
$PrveUrl = "{$this->PageUrl}p={$Prve}";
} else {
$PrveUrl = "{$this->PageUrl}p=1";
} return $PrveUrl;
} public function getNext($Page){
if ($Page != $this->CountPage) {
$Next = $Page + 1;
$NextUrl = "{$this->PageUrl}p={$Next}";
} else {
$NextUrl = "{$this->PageUrl}p={$this->CountPage}";
} return $NextUrl;
} }

PHP分页类,支持自定义样式,中间5页的更多相关文章

  1. TP5 分页类,自定义样式

    结合X-admin 后台框架 在做项目,为了保持分页风格的一致,所以需要自定义 一个分页类. 一.在项目的 extend 目录,创建 cus 目录 二.创建 Page 分页类,代码如下 <?ph ...

  2. 自己实现的数据表格控件(dataTable),支持自定义样式和标题数据、ajax等各种自定义设置以及分页自定义

    一.前言 也没什么好说的嘛,用了蛮多github上开源的能够实现dataTable功能的表格插件,不过都默认绑定样式啊,数据格式也设定的比较死,所以忍不住自己实现了一个简单的可自定义样式和自定义数据返 ...

  3. PHP+jQuery 列表分页类 ( 支持 url 分页 / ajax 分页 )

    /* ******* 环境:Apache2.2.8 ( 2.2.17 ) + PHP5.2.6 ( 5.3.3 ) + MySQL5.0.51b ( 5.5.8 ) + jQuery-1.8.3.mi ...

  4. 使ThinkPHP(3.2.3)的分页类支持Bootstrap风格

    ThinkPHP 3.2.3自带的分页类位于:/ThinkPHP/Library/Think/Pages.class.php ,官方文档在这里:ThinkPHP3.2.3数据分页 Pages.clas ...

  5. PHP+jQuery 长文章分页类 ( 支持 url / ajax 分页方式 )

    /* ******* 环境:Apache2.2.8 ( 2.2.17 ) + PHP5.2.6 ( 5.3.3 ) + MySQL5.0.51b ( 5.5.8 ) + jQuery-1.8 **** ...

  6. php分页类的二种调用方法(转载)

    php分页类的二种调用方法 原文地址:http://www.xfcodes.com/php/fenye/25584.htm 导读:php分页类的二种调用用法,ajax调用php分页类,非ajax方式调 ...

  7. asp.net的快捷实用分页类

    KeleyiPager分页类,可以于对列表页进行分页浏览,代码是从HoverTreeCMS项目中COPY的,感觉很不错,使用简单方便,但是功能强大. 在线体验效果:http://cms.hovertr ...

  8. php-数据库-分页类-上传类

    config.ini.php <?php header("content-type:text/html;charset=utf-8"); //项目的根目录 define(&q ...

  9. 好用的ASP.NET 分页类 简单好用 支持 AJAX 自定义文字

    在做网站没用 JS UI控件时 很实用 用法: var ps=new PageString(); /*可选参数*/ ps.SetIsEnglish = true;// 是否是英文 (默认:false) ...

随机推荐

  1. C#入门经典第九章定义类-1

    1.C#中使用class关键字来定义类 class MyClass { //代码部分 } 定义了类之后,就可以在项目中能访问该定义的其他位置对该类进行实例化.默认情况下,类的声明是内部的,即只有当前项 ...

  2. Git 学习资源

    在线教程 Try Git: Git初学者绝不能错过的Git上手资源. 廖雪峰Git教程: 比较系统的中文在线教程 易百Git教程 : 另一个比较全的中文在线教程 Git Immersion : A V ...

  3. ubuntu安装mysql数据库

    http://www.cnblogs.com/zhuyp1015/p/3561470.html http://www.2cto.com/database/201401/273423.html http ...

  4. 关于nodejs的require顺序

    --------------------------------------- check /home/somebody/node_modules/othermodule check /home/so ...

  5. ecos的model

    表->dbschema->model 虚拟化model机制 在dbschema存在model不存在的情况下 很多mvc结构都这么来 model命名规则 {$app_name}_mdl_{$ ...

  6. fuel健康检查Heat失败的原因

    service openstack-heat-engine restart chkconfig --level 2345 openstack-heat-engine on

  7. Nginx http_user_agent 防御 ab 等

    日志出现大量: xxxxxxxxxxxxx - - [04/Jul/2013:23:37:49 +0800] "GET /1000.html HTTP/1.0" 200 56471 ...

  8. Cordova3+sencha touch2.x 环境搭建

    1.安装 nodejs 2.安装 cordova: npm install -g cordova 3.创建一个工程: cordova create MyApp com.example.MyApp My ...

  9. 关于 HTML5、Jquery、Phonegap 跨域问题的研究

    近期研究Phonegap的相关技术,遇到了服务资源访问的跨域.经过尝试使用服务器端的代理,Phonegap打包后不能够访问到相应资源.在搜索引擎的帮助下,找到了Jquery的jsonp的方式,尝试发现 ...

  10. STM32 USB虚拟串口(转)

    源:STM32 USB虚拟串口 串口调试在项目中被使用越来越多,串口资源的紧缺也变的尤为突出.很多本本人群,更是深有体会,不准备一个USB转串口工具就没办法进行开发.本章节来简单概述STM32低端芯片 ...