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 相关文章推荐
Adodb的十个实例(清晰版)
Dec 31 PHP
php 删除无限级目录与文件代码共享
Nov 22 PHP
PHP命令行脚本接收传入参数的三种方式
Aug 20 PHP
PHP多线程类及用法实例
Dec 03 PHP
php的sso单点登录实现方法
Jan 08 PHP
php生成4位数字验证码的实现代码
Nov 23 PHP
php微信开发之批量生成带参数的二维码
Jun 26 PHP
Laravel下生成验证码的类
Nov 15 PHP
PHP使用两个栈实现队列功能的方法
Jan 15 PHP
PHP四种排序算法实现及效率分析【冒泡排序,插入排序,选择排序和快速排序】
Apr 27 PHP
PHP等比例压缩图片的实例代码
Jul 26 PHP
laravel 获取某个查询的查询SQL语句方法
Oct 12 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
《星际争霸重制版》兵种对比图鉴
2020/03/02 星际争霸
php实现最简单的MVC框架实例教程
2014/09/08 PHP
浅谈php中curl、fsockopen的应用
2016/12/10 PHP
javascript与CSS复习(三)
2010/06/29 Javascript
document.getElementById的简写方式(获取id对象的简略写法)
2010/09/10 Javascript
jQuery数据显示插件整合实现代码
2011/10/24 Javascript
如何让DIV可编辑、可拖动示例代码
2013/09/18 Javascript
原生js做的手风琴效果的导航菜单
2013/11/08 Javascript
Javascript中setTimeOut和setInterval的定时器用法
2015/06/12 Javascript
JavaScript生成图形验证码
2020/08/24 Javascript
AngularJS路由删除#符号解决的办法
2017/09/28 Javascript
基于node下的http小爬虫的示例代码
2018/01/11 Javascript
vue大型项目之分模块运行/打包的实现
2020/09/21 Javascript
vue中封装axios并实现api接口的统一管理
2020/12/25 Vue.js
介绍Python中的文档测试模块
2015/04/28 Python
python实现在遍历列表时,直接对dict元素增加字段的方法
2019/01/15 Python
Python线程之定位与销毁的实现
2019/02/17 Python
Python JSON格式数据的提取和保存的实现
2019/03/22 Python
Pandas之ReIndex重新索引的实现
2019/06/25 Python
python画图把时间作为横坐标的方法
2019/07/07 Python
Python pysnmp使用方法及代码实例
2020/08/24 Python
Python下载的11种姿势(小结)
2020/11/18 Python
css3的transform造成z-index无效解决方案
2014/12/04 HTML / CSS
HTML5 Canvas draw方法制作动画效果示例
2013/07/11 HTML / CSS
详解HTML5中的拖放事件(Drag 和 drop)
2016/11/14 HTML / CSS
印度化妆品购物网站:Nykaa
2018/07/22 全球购物
美体小铺奥地利官方网站:The Body Shop奥地利
2019/04/11 全球购物
2014年监理个人工作总结
2014/12/11 职场文书
2016春节慰问信范文
2015/03/25 职场文书
采购内勤岗位职责
2015/04/13 职场文书
新生开学寄语大全
2015/05/28 职场文书
2016幼儿园教师节新闻稿
2015/11/25 职场文书
2016春季运动会前导词
2015/11/25 职场文书
银行岗位培训心得体会
2016/01/09 职场文书
详解Node.js如何处理ES6模块
2021/05/15 Javascript
FFmpeg视频处理入门教程(新手必看)
2022/01/22 杂记