用ThinkPHP实现列表翻页效果

ThinkPHP也提供了翻页类,下面介绍一下具体的使用方法:

在控制器中引入翻页类:

import(‘ORG.Util.Page’);
//表中记录条数
$count = M(‘hope’)->count();
//实例化一个page对象,第一个参数是记录条数,第二个参数是每页显示的条数
$page = new Page($count,10);
$limit = $page->firstRow.’,’.$page->listRows;
//查询结果
$data = M(‘hope’)->order(‘time DESC’)->limit($limit)->select();
$this->assign(‘hope’,$data);
//前端模板中显示翻页按钮
$this->assign(‘page’,$page->show());
$this->display(‘index’);
注意,有的服务器不支持Index/index/uid/1/show/2这种格式,可以设置此参数为0,默认是1:

‘URL_MODEL’=>0,
(完)!