<?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. kafka configuration

    http://kafka.apache.org/08/configuration.html

  2. textbox文本键盘全选

    private void textBox1_KeyDown(object sender, KeyEventArgs e)        {            if (e.Modifiers == ...

  3. iOS的CocoaPods(activesupport requires Ruby version >= 2.2.2)

    如果你在安装遇到这个问题 activesupport requires Ruby version >= 2.2.2,那么这里可以帮助你(lasted version) 如果你是通过 http:/ ...

  4. 虚拟机安装tools for Ubuntu

    1.启动虚拟机,进入虚拟机 2.选定菜单中的虚拟机按钮,点击安装VMware Tools 3.此时虚拟机上会弹出一些文件,   复制VMwareTools-XXX-XX.tar.gz到桌面,鼠标右键可 ...

  5. HDU 4393 Throw nails(优先队列)

    优先队列的应用 好坑,好坑,好坑,重要的事情说三遍! #include<iostream> #include<cstdio> #include<cstring> # ...

  6. LoadRunner 录制cas 登陆脚本

    关于CAS 的概念,见链接:http://www.360doc.com/content/15/0204/17/21706453_446251626.shtml 需要增加4个关联函数 //Correla ...

  7. Python3基础 函数 收集参数+普通参数 的示例

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...

  8. stdarg.h头

    stdarg.h 头文件,主要目的是让函数可以接受可变参数. va_list :用来保存宏va_arg与宏va_end所需信息. va_start :使va_list指向起始的参数 va_arg :检 ...

  9. JS学习随手笔记

    ===================字符串===================== 字符串中间的空格也是要算长度的. 每一个字符都可以返回对应的Unicode 编码 文字的简单加密都是通过char ...

  10. Android WifiDisplay分析一:相关Service的启动

    网址:http://www.2cto.com/kf/201404/290996.html 最近在学习Android 4.4上面的WifiDisplay(Miracast)相关的模块,这里先从WifiD ...