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 上传功能实例代码
Apr 13 PHP
PHP执行linux系统命令的常用函数使用说明
Apr 27 PHP
PHP中MVC模式的模板引擎开发经验分享
Mar 23 PHP
PHP PDOStatement:bindParam插入数据错误问题分析
Nov 13 PHP
ini_set的用法介绍
Jan 07 PHP
PHP调试函数和日志记录函数分享
Jan 31 PHP
隐藏Nginx或Apache以及PHP的版本号的方法
Jan 03 PHP
php的4种常用运行方式详解
Dec 22 PHP
php常用数组函数实例小结
Dec 29 PHP
如何通过View::first使用Laravel Blade的动态模板详解
Sep 21 PHP
JSON PHP中,Json字符串反序列化成对象/数组的方法
May 31 PHP
tp5.1 实现setInc字段自动加1
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
解析WordPress中的post_class与get_post_class函数
2016/01/04 PHP
JavaScript面象对象设计
2008/04/28 Javascript
javascript实现表格排序 编辑 拖拽 缩放
2015/01/02 Javascript
Javascript实现div层渐隐效果的方法
2015/05/30 Javascript
JavaScript实现级联菜单的方法
2015/06/29 Javascript
javascript实现显示和隐藏div方法汇总
2015/08/14 Javascript
jQuery实现Tab菜单滚动切换的方法
2015/09/21 Javascript
FullCalendar日历插件应用之数据展现(一)
2015/12/23 Javascript
微信小程序 for 循环详解
2016/10/09 Javascript
详解在vue-cli项目中安装node-sass
2017/06/21 Javascript
使用原生js封装的ajax实例(兼容jsonp)
2017/10/12 Javascript
nodejs使用http模块发送get与post请求的方法示例
2018/01/08 NodeJs
vue 父组件给子组件传值子组件给父组件传值的实例代码
2019/04/15 Javascript
JavaScript 装逼指南(js另类写法)
2020/05/10 Javascript
javascript实现京东快递单号的查询效果
2020/11/30 Javascript
python3访问sina首页中文的处理方法
2014/02/24 Python
python实现杨辉三角思路
2017/07/14 Python
Python实现平行坐标图的两种方法小结
2019/07/04 Python
python中web框架的自定义创建
2019/09/08 Python
解决django后台管理界面添加中文内容乱码问题
2019/11/15 Python
利用Tensorflow的队列多线程读取数据方式
2020/02/05 Python
Python变量及数据类型用法原理汇总
2020/08/06 Python
详解pandas赋值失败问题解决
2020/11/29 Python
实例讲解利用HTML5 Canvas API操作图形旋转的方法
2016/03/22 HTML / CSS
办公文员的工作岗位职责
2013/11/12 职场文书
前台文员我鉴定
2014/01/12 职场文书
大学学习生活感言
2014/01/18 职场文书
人力资源总监工作说明
2014/03/03 职场文书
责任心演讲稿
2014/05/14 职场文书
2014年外贸业务员工作总结
2014/12/11 职场文书
大学生学期个人总结
2015/02/12 职场文书
新闻稿件写作范文
2015/07/18 职场文书
为什么阅读对所有年龄段的孩子都很重要?
2019/07/08 职场文书
使用Vue3+Vant组件实现App搜索历史记录功能(示例代码)
2021/06/09 Vue.js
javascript的setTimeout()使用方法总结
2021/11/20 Javascript
python运算符之与用户交互
2022/04/13 Python