fleaphp常用方法分页之Pager使用方法


Posted in PHP onApril 23, 2011

Pager 分页函数

/** 
* 构造函数 
* 
* 如果 $source 参数是一个 TableDataGateway 对象,则 FLEA_Helper_Pager 会调用 
* 该 TDG 对象的 findCount() 和 findAll() 来确定记录总数并返回记录集。 
* 
* 如果 $source 参数是一个字符串,则假定为 SQL 语句。这时,FLEA_Helper_Pager 
* 不会自动调用计算各项分页参数。必须通过 setCount() 方法来设置作为分页计算 
* 基础的记录总数。 
* 
* 同时,如果 $source 参数为一个字符串,则不需要 $conditions 和 $sortby 参数。 
* 而且可以通过 setDBO() 方法设置要使用的数据库访问对象。否则 FLEA_Helper_Pager 
* 将尝试获取一个默认的数据库访问对象。 
* 
* @param TableDataGateway|string $source 
* @param int $currentPage 
* @param int $pageSize 
* @param mixed $conditions 
* @param string $sortby 
* @param int $basePageIndex 
* 
* @return FLEA_Helper_Pager 
*/ 
function FLEA_Helper_Pager(& $source, $currentPage, $pageSize = 20, $conditions = null, $sortby = null, $basePageIndex = 0) 
{ 
$this->_basePageIndex = $basePageIndex; 
$this->_currentPage = $this->currentPage = $currentPage; 
$this->pageSize = $pageSize; 
if (is_object($source)) { 
$this->source =& $source; 
$this->_conditions = $conditions; 
$this->_sortby = $sortby; 
$this->totalCount = $this->count = (int)$this->source->findCount($conditions); 
$this->computingPage(); 
} elseif (!empty($source)) { 
$this->source = $source; 
$sql = "SELECT COUNT(*) FROM ( $source ) as _count_table"; 
$this->dbo =& FLEA::getDBO(); 
$this->totalCount = $this->count = (int)$this->dbo->getOne($sql); 
$this->computingPage(); 
} 
}

Pager 参数说明
$source 数据库操作类
$currentPage 当前页
$pageSize 每页显示记录数量
$conditions 查询条件
$sortby 排序方式
$basePageIndex 页码基数
Pager 使用示例(实例)
$dirname = dirname(__FILE__); 
define('APP_DIR', $dirname . '/APP'); 
define('NO_LEGACY_FLEAPHP', true); 
require($dirname.'/FleaPHP/FLEA/FLEA.php'); 
//设置缓存目录 
FLEA::setAppInf('internalCacheDir',$dirname.'/_Cache'); 
//链接数据库 
$dsn = array( 
'driver' => 'mysql', 
'host' => 'localhost', 
'login' => 'root', 
'password' => '', 
'database' => 'wordpress' 
); 
FLEA::setAppInf('dbDSN',$dsn); 
//读取wp_posts的内容 
FLEA::loadClass('FLEA_Db_TableDataGateway'); 
FLEA::loadClass('FLEA_Helper_Pager'); 
//FLEA::loadHelper('pager'); 
class Teble_Class extends FLEA_Db_TableDataGateway { 
var $tableName = 'wp_posts'; 
var $primaryKey = 'ID'; 
} 
$tableposts =& new Teble_Class(); 
$pager =& new FLEA_Helper_Pager($tableposts,2,5); 
$page = $pager->getPagerData(); 
print_r($page);

getPagerData 返回一些数据供调用
$data = array( 
'pageSize' => $this->pageSize, 
'totalCount' => $this->totalCount, 
'count' => $this->count, 
'pageCount' => $this->pageCount, 
'firstPage' => $this->firstPage, 
'firstPageNumber' => $this->firstPageNumber, 
'lastPage' => $this->lastPage, 
'lastPageNumber' => $this->lastPageNumber, 
'prevPage' => $this->prevPage, 
'prevPageNumber' => $this->prevPageNumber, 
'nextPage' => $this->nextPage, 
'nextPageNumber' => $this->nextPageNumber, 
'currentPage' => $this->currentPage, 
'currentPageNumber' => $this->currentPageNumber, 
);
PHP 相关文章推荐
40个迹象表明你还是PHP菜鸟
Sep 29 PHP
php for 循环语句使用方法详细说明
May 09 PHP
php全角字符转换为半角函数
Feb 07 PHP
Yii Framework框架获取分类下面的所有子类方法
Jun 20 PHP
PHP将字符分解为多个字符串的方法
Nov 22 PHP
PHP 错误处理机制
Jul 06 PHP
php进程间通讯实例分析
Jul 11 PHP
php常用字符串String函数实例总结【转换,替换,计算,截取,加密】
Dec 07 PHP
PHP中函数gzuncompress无法使用的解决方法
Mar 02 PHP
浅谈Yii乐观锁的使用及原理
Jul 25 PHP
php 字符串中是否包含指定字符串的多种方法
Apr 12 PHP
Laravel 前端资源配置教程
Oct 18 PHP
PHP中限制IP段访问、禁止IP提交表单的代码
Apr 23 #PHP
PHP计划任务、定时执行任务的实现代码
Apr 23 #PHP
PHP导入Excel到MySQL的方法
Apr 23 #PHP
在php和MySql中计算时间差的方法
Apr 22 #PHP
PHP遍历二维数组的代码
Apr 22 #PHP
PHP中调用ASP.NET的WebService的代码
Apr 22 #PHP
PHP中输出转义JavaScript代码的实现代码
Apr 22 #PHP
You might like
基于mysql的bbs设计(一)
2006/10/09 PHP
phpmyadmin里面导入sql语句格式的大量数据的方法
2010/06/05 PHP
PHP数组 为文章加关键字连接 文章内容自动加链接
2011/12/29 PHP
W3C Group的JavaScript1.8 新特性介绍
2009/05/19 Javascript
jQuery+CSS 实现的超Sexy下拉菜单
2010/01/17 Javascript
Javascript 去除数组的重复元素
2010/05/04 Javascript
13个绚丽的Jquery 界面设计网站推荐
2010/09/28 Javascript
javascript学习笔记(十二) RegExp类型介绍
2012/06/20 Javascript
当前页禁止复制粘贴截屏代码小集
2013/07/24 Javascript
JS 实现BASE64_ENCODE和BASE64_DECODE(实例代码)
2013/11/13 Javascript
js 实现菜单上下显示附效果图
2013/11/21 Javascript
jQuery中element选择器用法实例
2014/12/29 Javascript
javascript判断网页是关闭还是刷新
2015/09/12 Javascript
javascript实现平滑无缝滚动
2020/08/09 Javascript
Angular实现点击按钮后在上方显示输入内容的方法
2017/12/27 Javascript
Vue中用props给data赋初始值遇到的问题解决
2018/11/27 Javascript
基于layui框架响应式布局的一些使用详解
2019/09/16 Javascript
vue 解决遍历对象显示的顺序不对问题
2019/11/07 Javascript
JavaScript实现省市区三级联动
2020/02/13 Javascript
[42:32]DOTA2上海特级锦标赛B组资格赛#2 Fnatic VS Spirit第二局
2016/02/27 DOTA
python实现批量下载新浪博客的方法
2015/06/15 Python
浅谈python多线程和队列管理shell程序
2015/08/04 Python
教你学会使用Python正则表达式
2017/09/07 Python
tensorflow estimator 使用hook实现finetune方式
2020/01/21 Python
python实现字符串和数字拼接
2020/03/02 Python
浅谈html5之sse服务器发送事件EventSource介绍
2017/08/28 HTML / CSS
canvas因为图片资源不在同一域名下而导致的跨域污染画布的解决办法
2019/01/18 HTML / CSS
Sport-Thieme荷兰:购买体育用品
2019/08/25 全球购物
配置管理计划的主要内容有哪些
2014/06/20 面试题
工程部经理岗位职责
2013/12/08 职场文书
校园联欢晚会主持词
2014/03/17 职场文书
铣床操作工岗位职责
2014/06/13 职场文书
教师党员自我剖析材料
2014/09/29 职场文书
毕业生班级鉴定评语
2015/01/04 职场文书
2016幼儿园毕业感言
2015/12/08 职场文书
JavaScript设计模式之原型模式详情
2022/06/21 Javascript