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 相关文章推荐
dedecms模版制作使用方法
Apr 03 PHP
解析php中的fopen()函数用打开文件模式说明
Jun 20 PHP
PHP实现将视频转成MP4并获取视频预览图的方法
Mar 12 PHP
Yii中表单用法实例详解
Jan 05 PHP
Ubuntu server 11.04安装memcache及php使用memcache来存储session的方法
May 31 PHP
php getcwd与dirname(__FILE__)区别详解
Sep 24 PHP
Yii2.0多文件上传实例说明
Jul 24 PHP
PHP实现使用DOM将XML数据存入数组的方法示例
Sep 27 PHP
Ajax中的JSON格式与php传输过程全面解析
Nov 14 PHP
PHP中register_shutdown_function函数的基础介绍与用法详解
Nov 28 PHP
PHP多进程通信-消息队列使用
Mar 08 PHP
tp5.1 框架数据库-数据集操作实例分析
May 26 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
Symfony数据校验方法实例分析
2015/01/26 PHP
php实现的debug log日志操作类实例
2016/07/12 PHP
Yii使用DeleteAll连表删除出现报错问题的解决方法
2016/07/14 PHP
PHP通过调用新浪API生成t.cn格式短网址链接的方法详解
2019/02/20 PHP
php使用gearman进行任务分发操作实例详解
2020/02/26 PHP
用JavaScript对JSON进行模式匹配 (Part 2 - 实现)
2010/07/17 Javascript
封装html的select标签的js操作实例
2013/07/02 Javascript
js动态修改整个页面样式达到换肤效果
2014/05/23 Javascript
node.js中的fs.lstatSync方法使用说明
2014/12/16 Javascript
JavaScript中数据结构与算法(一):栈
2015/06/19 Javascript
关于在Servelet中如何获取当前时间的操作方法
2016/06/28 Javascript
JavaScript的==运算详解
2016/07/20 Javascript
在localStorage中存储对象数组并读取的方法
2016/09/24 Javascript
jQuery实现点击任意位置弹出层外关闭弹出层效果
2016/10/19 Javascript
canvas的神奇用法
2017/02/03 Javascript
详解vue的数据binding绑定原理
2017/04/12 Javascript
JavaScript中各数制转换全面总结
2017/08/21 Javascript
iview中Select 选择器多选校验方法
2018/03/15 Javascript
微信小程序页面间传值与页面取值操作实例分析
2019/04/30 Javascript
Vue开发中遇到的跨域问题及解决方法
2020/02/11 Javascript
小程序选项卡以及swiper套用(跨页面)
2020/06/19 Javascript
JS事件循环机制event loop宏任务微任务原理解析
2020/08/04 Javascript
[00:32]2018DOTA2亚洲邀请赛出场——VP
2018/04/04 DOTA
Windows下Eclipse+PyDev配置Python+PyQt4开发环境
2016/05/17 Python
PyChar学习教程之自定义文件与代码模板详解
2017/07/17 Python
Python爬虫之Selenium鼠标事件的实现
2020/12/04 Python
美国南部最大的家族百货公司:Belk
2017/01/30 全球购物
美国林业供应商:Forestry Suppliers
2019/05/01 全球购物
自我评价范文
2013/12/22 职场文书
何玥事迹观后感
2015/06/16 职场文书
社区安全温馨提示语
2015/07/14 职场文书
教师节作文之小学四年级
2019/09/03 职场文书
了解Redis常见应用场景
2021/06/23 Redis
vue实现列表垂直无缝滚动
2022/04/08 Vue.js
Windows server 2003卸载和安装IIS的图文教程
2022/07/15 Servers
TS 类型兼容教程示例详解
2022/09/23 Javascript