<?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. ubuntu上面安装eclipse android到adt下载方法

    如果自动安装有问题的话,就需要手动安装,其实是差不多的,唯一不同的就是手动下载ADT插件包,http://dl.google.com/android/ADT-0.9.6.zip ,可以下载到. 版本号 ...

  2. 加密Web.Config配置文件

    protected void btnPassWord_Click(object sender, EventArgs e) { //加密 Configuration config = WebConfig ...

  3. tcp 的6个控制位

    原文:http://blog.chinaunix.net/uid-26413668-id-3376762.html TCP(Transmission Control Protocol) 传输控制协议 ...

  4. OpenGL学习--------颜色的选择

    OpenGL支持两种颜色模式:一种是RGBA,一种是颜色索引模式.无论哪种颜色模式,计算机都必须为每一个像素保存一些数据.不同的是,RGBA模式中,数据直接就代表了颜色:而颜色索引模式中,数据代表的是 ...

  5. MJRefresh

    automaticallyChangeAlpha 下拉或上拉时,文字颜色逐渐加深

  6. 在Gridview编辑时添加DropDownList控件并设置默认值

    页面代码: <asp:GridView ID="GridView1" runat="server"             AutoGenerateCol ...

  7. Android PopupWindow的使用技巧(转)

    Android PopupWindow的使用技巧 PopupWindow是Android上自定义弹出窗口,使用起来很方便. PopupWindow的构造函数为 public PopupWindow(V ...

  8. Java回调函数的理解

    所谓回调,就是客户程序C调用服务程序S中的某个函数A,然后S又在某个时候反过来调用C中的某个函数B,对于C来说,这个B便叫做回调函数.例如Win32下的窗口过程函数就是一个典型的回调函数.一般说来,C ...

  9. Ubuntu 下开发 Android 环境变量设置

    -----------------------------------------------------ANDROID_SDK_HOME:/home/cmm/avds PATH:/home/cmm/ ...

  10. 利用ZjDroid对 <捕鱼达人3> 脱壳及破解过程-转

    http://blog.sina.com.cn/zihao2015 <捕鱼达人3> 刚出来不久,就被鬼哥Dump出来dex,随之破解也就轻而易举.一开始我用ZjDroid神器试验过,但是没 ...