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 相关文章推荐
随机广告显示(PHP函数)
Oct 09 PHP
php与XML、XSLT、Mysql的结合运用实现代码
Nov 19 PHP
配置php.ini实现PHP文件上传功能
Nov 27 PHP
浅谈PDO的rowCount函数
Jun 18 PHP
PHP  实现等比压缩图片尺寸和大小实例代码
Oct 08 PHP
PHP+mysql+ajax轻量级聊天室实现方法详解
Oct 17 PHP
[原创]php使用strpos判断字符串中数字类型子字符串出错的解决方法
Apr 01 PHP
PHP删除数组中指定下标的元素方法
Feb 03 PHP
php workerman定时任务的实现代码
Dec 23 PHP
PHP PDOStatement::setFetchMode讲解
Feb 03 PHP
PHP中单例模式的使用场景与使用方法讲解
Mar 18 PHP
Laravel jwt 多表(多用户端)验证隔离的实现
Dec 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
php URL验证正则表达式
2011/07/19 PHP
Thinkphp搭建包括JS多语言的多语言项目实现方法
2014/11/24 PHP
PHP的pcntl多进程用法实例
2015/03/19 PHP
PHP通过curl获取接口URL的数据方法
2018/05/31 PHP
PHP实现二维数组按照指定的字段进行排序算法示例
2019/04/23 PHP
深入理解javascript动态插入技术
2013/11/12 Javascript
Iframe实现跨浏览器自适应高度解决方法
2014/09/02 Javascript
关于编写性能高效的javascript事件的技术
2014/11/28 Javascript
js实现简单鼠标跟随效果的方法
2015/04/10 Javascript
jQuery插件scroll实现无缝滚动效果
2015/04/27 Javascript
js显示当前日期时间和星期几
2015/10/22 Javascript
JS中生成随机数的用法及相关函数
2016/01/09 Javascript
基于JavaScript判断浏览器到底是关闭还是刷新(超准确)
2016/02/01 Javascript
微信小程序-获得用户输入内容
2017/02/13 Javascript
微信小程序开发之麦克风动画 帧动画 放大 淡出
2017/04/18 Javascript
JavaScript正则表达式校验与递归函数实际应用实例解析
2017/08/04 Javascript
详解React开发必不可少的eslint配置
2018/02/05 Javascript
[01:09:16]DOTA2-DPC中国联赛 正赛 SAG vs Dynasty BO3 第一场 1月25日
2021/03/11 DOTA
使用Python3制作TCP端口扫描器
2017/04/17 Python
实用自动化运维Python脚本分享
2018/06/04 Python
Python实现的NN神经网络算法完整示例
2018/06/19 Python
强悍的Python读取大文件的解决方案
2019/02/16 Python
Python元组知识点总结
2019/02/18 Python
django框架防止XSS注入的方法分析
2019/06/21 Python
python连接打印机实现打印文档、图片、pdf文件等功能
2020/02/07 Python
Python如何使用paramiko模块连接linux
2020/03/18 Python
python3中的logging记录日志实现过程及封装成类的操作
2020/05/12 Python
python和php哪个容易学
2020/06/19 Python
Python 求向量的余弦值操作
2021/03/04 Python
《值日生》教学反思
2014/02/17 职场文书
欢度春节标语
2014/07/01 职场文书
转让协议书范本
2014/09/13 职场文书
2014年控辍保学工作总结
2014/12/08 职场文书
幼师辞职信范文
2015/02/27 职场文书
质检员工作总结2015
2015/04/25 职场文书
《女娲补天》读后感5篇
2019/12/31 职场文书