thinkPHP生成静态分页列表
改造分页类Pagehtml.class.php
<?php
// 静态分页列表类
class Pagehtml extends Think {
//分页url
public $pageUrl;
// 起始行数
public $firstRow ;
// 列表每页显示行数
public $listRows ;
// 分页总页面数
protected $totalPages ;
// 总行数
protected $totalRows ;
// 当前页数
protected $nowPage ;
// 分页的栏的总页数
protected $coolPages ;
// 分页栏每页显示的页数
protected $rollPage ;
// 分页显示定制
protected $config = array('header'=>'条记录','prev'=>'上一页','next'=>'下一页','first'=>'第一页','last'=>'最后一页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页 %upPage% %downPage% %first% %prePage% %linkPage% %nextPage% %end%');
/**
+----------------------------------------------------------
* 架构函数
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param array $totalRows 总的记录数
* @param array $listRows 每页显示记录数
* @param array $parameter 分页跳转的参数
+----------------------------------------------------------
*/
public function __construct($totalRows,$listRows,$pageUrl='',$nowPage) {
$this->pageUrl = $pageUrl;
$this->totalRows = $totalRows;
$this->rollPage = 5;
$this->listRows = !empty($listRows)?$listRows:C('PAGE_LISTROWS');
$this->totalPages = ceil($this->totalRows/$this->listRows); //总页数
$this->coolPages = ceil($this->totalPages/$this->rollPage);
$this->nowPage = $nowPage;
if(!empty($this->totalPages) && $this->nowPage>$this->totalPages) {
$this->nowPage = $this->totalPages;
}
$this->firstRow = $this->listRows*($this->nowPage-1);
}
public function setConfig($name,$value) {
if(isset($this->config[$name])) {
$this->config[$name] = $value;
}
}
/**
+----------------------------------------------------------
* 分页显示输出
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function show() {
if(0 == $this->totalRows) return '';
$nowCoolPage = ceil($this->nowPage/$this->rollPage);
$url = $this->pageUrl;
//上下翻页字符串
$upRow = $this->nowPage-1;
$downRow = $this->nowPage+1;
if ($upRow>0){
if($upRow==1){
$upPage="<a href='".$url.".html'>".$this->config['prev']."</a>";
}else{
$upPage="<a href='".$url."_$upRow.html'>".$this->config['prev']."</a>";
}
}else{
$upPage="";
}
if ($downRow <= $this->totalPages){
$downPage="<a href='".$url."_$downRow.html'>".$this->config['next']."</a>";
}else{
$downPage="";
}
// << < > >>
if($nowCoolPage == 1){
$theFirst = "";
$prePage = "";
}else{
$preRow = $this->nowPage-$this->rollPage;
if($preRow==1){
$prePage = "";
}else{
$prePage = "<a href='".$url."_$preRow.html' >上".$this->rollPage."页</a>";
}
$theFirst = "<a href='".$url.".html' >".$this->config['first']."</a>";
}
if($nowCoolPage == $this->coolPages){
$nextPage = "";
$theEnd="";
}else{
$nextRow = $this->nowPage+$this->rollPage;
$theEndRow = $this->totalPages;
if($nextRow>= $this->totalPages){
$nextPage = "";
}else{
$nextPage = "<a href='".$url."_$nextRow.html' >下".$this->rollPage."页</a>";
}
$theEnd = "<a href='".$url."_$theEndRow.html' >".$this->config['last']."</a>";
}
// 1 2 3 4 5
$linkPage = "";
for($i=1;$i<=$this->rollPage;$i++){
$page=($nowCoolPage-1)*$this->rollPage+$i;
if($page!=$this->nowPage){
if($page<=$this->totalPages){
if($page==1){
$linkPage .= " <a href='".$url.".html'> ".$page." </a>";
}else{
$linkPage .= " <a href='".$url."_$page.html'> ".$page." </a>";
}
}else{
break;
}
}else{
if($this->totalPages != 1){
$linkPage .= " <span class='current'>".$page."</span>";
}
}
}
$pageStr = str_replace(
array('%header%','%nowPage%','%totalRow%','%totalPage%','%upPage%','%downPage%','%first%','%prePage%','%linkPage%','%nextPage%','%end%'),
array($this->config['header'],$this->nowPage,$this->totalRows,$this->totalPages,$upPage,$downPage,$theFirst,$prePage,$linkPage,$nextPage,$theEnd),$this->config['theme']);
return $pageStr;
}
}
?>
生成代码:
public function make_list(){
header("Content-type: text/html; charset=utf-8");
import("@.ORG.Pagehtml");
$model = M('Menu');
$count = $model->count();
$totalPage = ceil($count/2);
for($i=1;$i<=$totalPage;$i++){
$Page = new Pagehtml($count,2,"http://easyui.demo/news/list",$i);
$show = $Page->show();
$Page->firstRow = $i-1;
$list = $model->query("select * from hs_menu order by rtime desc limit $Page->firstRow,$Page->listRows");
$this->assign('page',$show);
$this->assign('list',$list);
if($i==1){
$htmlfile = "list";
}else{
$htmlfile = "list_$i";
}
$htmlpath = getcwd()."/news/";
$templateFile = "home:Game:_list";
$res = $this->buildHtml($htmlfile,$htmlpath,$templateFile);
echo "静态页面$htmlfile.html已生成...<br>";
}
echo "ok";
}
模板文件:
home分组下Game控制器下_list方法
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<ul>
<volist name="list" id="vo">
<li>{$vo.name}</li>
</volist>
</ul>
<div>
{$page}
</div>
</body>
</html>
GameAction.class.php
class GameAction extends Action {
public function _list(){
$this->display('list');
}
}
thinkPHP生成静态分页列表的更多相关文章
- ThinkPHP生成静态页buildHtml方法
原来ThinkPHP自带了生成静态页的函数buildHtml,使用起来很方便!最新的手册里没写这个方法,向大家介绍一下. PHP 1 2 3 4 5 6 7 8 9 10 11 protect ...
- ThinkPhp 生成静态页面
//开启静态缓存'HTML_CACHE_ON' => true, //开启缓存'HTML_CACHE_TIME' =>60, //开启缓存时间'HTML_FILE_SUFFIX' => ...
- html模板生成静态页面及模板分页处理
它只让你修改页面的某一部分,当然这"某一部分"是由你来确定的.美工先做好一个页面,然后我们把这个页面当作模板(要注意的是这个模板就没必要使用EditRegion3这样的代码了,这种 ...
- .NET生成静态页面并分页
因为公司的产品用asp开发, 前一段时间用asp写了一个生成静态页面并分页的程序,但缘于对.net的热爱,写了这个.net下的生成静态页面并分页的程序. 主要的原理就是替换模板里的特殊字符. 1.静态 ...
- mvc分页生成静态页,mvc生成静态页
http://blog.csdn.net/xxj_jing/article/details/7899125 分页生成静态页 http://www.cnblogs.com/luanyilin/archi ...
- ThinkPHP 3.2 生成静态页面
1:在根目录下的全局index.php中加下面这行: define('HTML_PATH', './htm');//生成静态页面的文件位置 2:在项目的配置文件config.php中加下面这行: 'H ...
- ASP.NET MVC 解析模板生成静态页一(RazorEngine)
简述 Razor是ASP.NET MVC 3中新加入的技术,以作为ASPX引擎的一个新的替代项.在早期的MVC版本中默认使用的是ASPX模板引擎,Razor在语法上的确不错,用起来非常方便,简洁的语法 ...
- 浅谈php生成静态页面
一.引 言 在速度上,静态页面要比动态页面的比方php快很多,这是毫无疑问的,但是由于静态页面的灵活性较差,如果不借助数据库或其他的设备保存相关信息的话,整体的管理上比较繁琐,比方修改编辑.比方阅读权 ...
- 基于PHP生成静态页的实现方法
t1.php 复制代码 代码如下: <?php// 方法一根据模版生成静态页面// replaceTemplateString函数用于替换模板中指定字符串function replaceTemp ...
随机推荐
- redis的lua使用(EVALSHA)
redis 127.0.0.1:6379> SCRIPT LOAD "local list=redis.call('KEYS', KEYS[1] .. '*') return (tab ...
- ThinkPHP之中的getField、Find、select、返回数据类型详解(ThinkPHP之中所有数据读取了)
小李子:用于演示作用的数据库表:customers 官方解读: “ 读取数据集其实就是获取数据表中的多行记录(以及关联数据),使用select方法 ” $customers=D('customers' ...
- 使用c#检测文件正在被那个进程占用 判断文件是否被占用的两种方法
C# 判断文件是否被占用的三种方法 using System.IO; using System.Runtime.InteropServices; [DllImport("kernel32.d ...
- django-url调度器-高级篇
我们在中级篇中学会了如何进行反向解析,但是有这样一个问题,在为 url 命名的时候,名字不能重复,否则会导致各种各样的问题.在 url 还少的时候保证不重名还是比较简单的,但是 url 多起来以后就比 ...
- python 使用联动优势支付接口的sign与verify
直接上代码 if options.umpay_private_key is not None and len(options.umpay_private_key) > 0: try: with ...
- 【J2EE】Hibernate
Hibernate是面向Java环境的对象/关系数据库映射工具,管理Java应用和数据库之间的映射关系,提供数据查询和获取数据的方法,可以大幅减少使用JDBC处理数据持久化的时间. 使用Eclipse ...
- hdu 1429 胜利大逃亡(续)
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1429 胜利大逃亡(续) Description Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王 ...
- 用Java实现3DES
3DES,即三重DES,是DES的加强版,也是DES的一个更安全的变形.它使用3个56位(共168位)的密钥对数据进行三次加密,和DES相比,安全性得到了较大的提高. 实际上,3DES是一个过渡的加密 ...
- 5.Knockout.Js(自定义绑定)
前言 你可以创建自己的自定义绑定 – 没有必要非要使用内嵌的绑定(像click,value等).你可以你封装复杂的逻辑或行为,自定义很容易使用和重用的绑定.例如,你可以在form表单里自定义像grid ...
- [转]WinExec、ShellExecute和CreateProcess及返回值判断方式
[转]WinExec.ShellExecute和CreateProcess及返回值判断方式 http://www.cnblogs.com/ziwuge/archive/2012/03/12/23924 ...