<?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. Android音乐编程:管理音频焦点

    Android 系统保持相互独立的音频流通道来播放音乐,报警,通知,来电铃声,系统声音,呼叫(通话)音量,和 DTMF 音调(键盘拨号).这样做主要是为了使用户能够独立地控制每个流的音量. AD: h ...

  2. 转 :Oracle分区表 (Partition Table) 的创建及管理

    三.删除分区 You can drop partitions from range, list, or composite range-list partitioned tables. ALTER T ...

  3. sql server 行转列 Pivot UnPivot

    SQL Server中行列转换 Pivot UnPivot 本文转自:张志涛 原文地址: http://www.cnblogs.com/zhangzt/archive/2010/07/29/17878 ...

  4. Java之Property类使用

    http://blog.csdn.net/hopestar2/article/details/6372883 在项目中经常用到各种配置文件,有.properties的,也有.xml格式的 都可以通过j ...

  5. Delphi引用C对象文件(转)

    源:http://blog.csdn.net/henreash/article/details/7357618 C语言应用非常广泛,并在世界各地拥有大量的代码库.这些代码库与Delphi的可比性较小, ...

  6. centos lvm常用命令

    # vgs -a  VG     #PV #LV #SN Attr   VSize  VFree  cinder   1   0   0 wz--n- 30.39g 30.39g  os       ...

  7. struts2-----新建项目

    1. 建立界面原型 2. 建立Struts.xml 确定namespace, package, action, 空方法, result, 界面原型修改, 匹配现有设置, 测试, 做好规划 3. 建立数 ...

  8. [JSP] c:forEach 如何输出序号 - luotangsha的专栏 - 博客频道 - CSDN.NET

    [JSP] c:forEach 如何输出序号 分类: JSP 2011-06-24 01:36 13018人阅读 评论(2) 收藏 举报 jspcbordertable 关键在于<c:forEa ...

  9. CodeForces 660A Co-prime Array

    水题.放个1就可以了.暴力的找数字也是很快的. #include<cstdio> #include<cstring> #include<cmath> #includ ...

  10. (中等) HDU 3416 Marriage Match IV,SPFA+SAP。

    Description Do not sincere non-interference. Like that show, now starvae also take part in a show, b ...