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 ...
随机推荐
- 往Android SDCard中读写入数据
一.用Environment (写) 1.API获取sdcard的路径 File path=Environment.getExternalStorageDirectory(); path=new Fi ...
- onClick事件实现方式(打电话为例子)
1.在button 中 android:onclick="call" 注意事项:①.方法的名字必须是call ②.区别大小写 ③.call方法必须接收一个View类型的参数 ④.方 ...
- Microsoft Visual C++ Runtime error解决方法
1: 当出现下图时提示Microsoft Visual C++ Runtime error 2:此时不要关闭该对话框,然后打开任务管理器(Ctrl+Shift+Esc)如下图: 找到Microsoft ...
- asp.net解析请求报文
NameValueCollection myHeader = new NameValueCollection(); int i; string strKey; string result; myHea ...
- Mongodb初学习--安装、试用
MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. 在MongoDB中数据被分组存储在数据集中,被称为一个集合(Collection ...
- xtrabackup之Innobackupex全备恢复
一.当前环境 [mysql@hadoop1 ~]$ mysql --defaults-/my.cnf -uroot -p123456 -P3306 mysql> show variables l ...
- yhd日志分析(二)
yhd日志分析(二) 继续yhd日志分析,统计数据 日期 uv pv 登录人数 游客人数 平均访问时长 二跳率 独立ip数 1 分析 登录人数 count(distinct endUserId) 游客 ...
- 第四节:监视AppDomain
宿主应用程序可监视AppDomain消耗的资源.有的宿主根据这种信息判断一个AppDomain的内存或CPU消耗是否超过了应有的水准,并强制卸载一个AppDomain. 还可以利用监视来比较不同算法的 ...
- Python开发【第一篇】Python基础之生成器和迭代器
生成器和迭代器 1.生成器 一个函数调用时返回一个迭代器,那这个函数就叫做生成器(generator):如果函数中包含yield语法,那这个函数就会变成生成器: def func(): yield 1 ...
- Android触摸屏配置调试
前几天搞乐蛙时,进入后是鼠标模式,好坑爹的模式有木有~~ 但是大蛋给出了解决方法,我不怕不怕啦~让我们向大牛致敬!!! 首先输入Command查看你的input配置~ adb shell dumpsy ...