page.class.php

<?php
namespace Component;
class Page { private $total; //数据表中总记录数
private $listRows; //每页显示行数
private $limit;
private $uri;
private $pageNum; //页数
private $config = array('header' => "个记录", "prev" => "上一页", "next" => "下一页", "first" => "首 页", "last" => "尾 页");
private $listNum = 8; /*
* $total
* $listRows
*/ public function __construct($total, $listRows = 10, $pa = "") {
$this->total = $total;
$this->listRows = $listRows;
$this->uri = $this->getUri($pa);
$this->page = !empty($_GET["page"]) ? $_GET["page"] : 1;
$this->pageNum = ceil($this->total / $this->listRows);
$this->limit = $this->setLimit();
} private function setLimit() {
return "Limit " . ($this->page - 1) * $this->listRows . ", {$this->listRows}";
} private function getUri($pa) {
$url = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], '?') ? '' : "?") . $pa;
$parse = parse_url($url); if (isset($parse["query"])) {
parse_str($parse['query'], $params);
unset($params["page"]);
$url = $parse['path'] . '?' . http_build_query($params);
} return $url;
} function __get($args) {
if ($args == "limit")
return $this->limit;
else
return null;
} private function start() {
if ($this->total == 0)
return 0;
else
return ($this->page - 1) * $this->listRows + 1;
} private function end() {
return min($this->page * $this->listRows, $this->total);
} private function first() {
$html = "";
if ($this->page == 1)
$html .= '';
else
$html .= "  <a href='{$this->uri}&page=1'>{$this->config["first"]}</a>  "; return $html;
} private function prev() {
$html = "";
if ($this->page == 1)
$html .= '';
else
$html .= "  <a href='{$this->uri}&page=" . ($this->page - 1) . "'>{$this->config["prev"]}</a>  "; return $html;
} private function pageList() {
$linkPage = ""; $inum = floor($this->listNum / 2); for ($i = $inum; $i >= 1; $i--) {
$page = $this->page - $i; if ($page < 1)
continue; $linkPage .= " <a href='{$this->uri}&page={$page}'>{$page}</a> ";
} $linkPage .= " {$this->page} "; for ($i = 1; $i <= $inum; $i++) {
$page = $this->page + $i;
if ($page <= $this->pageNum)
$linkPage .= " <a href='{$this->uri}&page={$page}'>{$page}</a> ";
else
break;
} return $linkPage;
} private function next() {
$html = "";
if ($this->page == $this->pageNum)
$html .= '';
else
$html .= "  <a href='{$this->uri}&page=" . ($this->page + 1) . "'>{$this->config["next"]}</a>  "; return $html;
} private function last() {
$html = "";
if ($this->page == $this->pageNum)
$html .= '';
else
$html .= "  <a href='{$this->uri}&page=" . ($this->pageNum) . "'>{$this->config["last"]}</a>  "; return $html;
} private function goPage() {
return '  <input type="text" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>' . $this->pageNum . ')?' . $this->pageNum . ':this.value;location=\'' . $this->uri . '&page=\'+page+\'\'}" value="' . $this->page . '" style="width:25px"><input type="button" value="跳转" onclick="javascript:var page=(this.previousSibling.value>' . $this->pageNum . ')?' . $this->pageNum . ':this.previousSibling.value;location=\'' . $this->uri . '&page=\'+page+\'\'">  ';
} function fpage($display = array(0, 1, 2, 3, 4, 5, 6, 7, 8)) {
$html[0] = "  共有<b>{$this->total}</b>{$this->config["header"]}  ";
// $html[1] = "  每页显示<b>" . ($this->end() - $this->start() + 1) . "</b>条,本页<b>{$this->start()}-{$this->end()}</b>条  ";
$html[2] = "  <b>{$this->page}/{$this->pageNum}</b>页  "; $html[3] = $this->first();
$html[4] = $this->prev();
$html[5] = $this->pageList();
$html[6] = $this->next();
$html[7] = $this->last();
$html[8] = $this->goPage();
$fpage = '';
foreach ($display as $index) {
$fpage .= $html[$index];
} return $fpage;
} }

  

控制器调用方法:

function serverlist(){
$goods = D(ops_gz);
//总页数计算
$count = $goods->count();
$per = 10;
//实例化分页类
$page = new \Component\page($count,$per);
//拼装sql语句
$sql = "select * from ops_gz ".$page->limit;
$info = $goods->query($sql);
//获取页码列表
$pagelist = $page->fpage();
$this->assign(info,$info);
$this->assign(pagelist,$pagelist);
$this->display();
}

view

php分页类的实现与调用 (自我摘记)的更多相关文章

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

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

  2. php分页类 可直接调用

    <?php /** * 分页类 * @author xyy * 调用分页实例 $subPages=new SubPages(数据总条数);//实例化分页类 * //$subPages->s ...

  3. php实现的分页类

    php分页类文件: <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 pr ...

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

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

  5. PHPCMS V9 分页类的修改教程

    首先,打开 phpcms\libs\functions\global.func.php 这个文件,找到文件第622行的分页函数,复制一下,粘贴到默认分页函数的下面,重新命名后保存.(笔者在此命名为:p ...

  6. php 简单分页类

    /**  file: page.class.php   完美分页类 Page  */ class Page {  private $total;          //数据表中总记录数  privat ...

  7. php部分---一个分页类、用法

    1.分页类 <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 privat ...

  8. webpy分页类 + 上传类

    webpy没有分页类.按照php的思路.自己编了一个.数据库用的是sqlite. class Page(object): '''分页类''' def __init__(self,page_size,d ...

  9. php分页类代码带分页样式效果(转)

    php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...

随机推荐

  1. mysql如何配置sql记录

    原文链接:http://www.qqdeveloper.com/detail/11/1.html 为什么要记录sql记录 主要目的是为了检测我们的网站安全问题,有效的避免一些sql注入或者是xss攻击 ...

  2. Java异常链

    是什么 一种面向对象的编程技术,将捕获到的异常重新封装到一个新的异常中,并重新抛出. 有什么用 可以保留每一层的异常信息,用户查看异常的时候,能够从顶层异常信息看到底层异常信息. 怎么用 catch异 ...

  3. Python3 urllib 与 Python2 urllib的变化

    Infi-chu: http://www.cnblogs.com/Infi-chu/ Py2.x: Urllib库 Urllin2库 Py3.x: Urllib库 变化: 在Pytho2.x中使用im ...

  4. Linux 中的权限

    ABCD A-0, 十进制 B-user(u, 用户) C-group(g, 组用户) D-others(o, 其他用户) +-----+---+--------------------------+ ...

  5. 观看杨老师(杨旭)Asp.Net Core MVC入门教程记录

    观看杨老师(杨旭)Asp.Net Core MVC入门教程记录 ASP.NET Core MVC入门 Asp.Net Core启动和配置 Program类,Main方法 Startup类 依赖注入,I ...

  6. 使用putty远程登录Ubuntu时,报Network error:Connection refused错误及解决

    putty远程登录Ubuntu,弹出Network error:Connection refused的错误提示框,就是因为Ubuuntu没有安装ssh服务. 执行命令: sudo apt instal ...

  7. 北京Uber优步司机奖励政策(1月16日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  8. 【机器学习笔记】自组织映射网络(SOM)

    什么是自组织映射? 一个特别有趣的无监督系统是基于竞争性学习,其中输出神经元之间竞争激活,结果是在任意时间只有一个神经元被激活.这个激活的神经元被称为胜者神经元(winner-takes-all ne ...

  9. #3.14 Piday#我的圆周率日

    本文来自网易云社区 作者:马宝 圆周率日(Pi day) 2011年国际数学协会正式宣布,将每年的3月14日设为国际数学节,来源则是中国古代数学家祖冲之的圆周率."终极"圆周率日是 ...

  10. 获取附加在方法上的Attribute

    如下: class Program { static void Main(string[] args) { var methodInfo = typeof(Program).GetMethod(&qu ...