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
第十二节--类的自动加载
Nov 16 PHP
模板引擎Smarty深入浅出介绍
Dec 06 PHP
给apache2.2加上mod_encoding模块後 php5.2.0 处理url出现bug
Apr 12 PHP
php 判断字符串中是否包含html标签
Feb 17 PHP
PHP APC配置文件2套和参数详解
Jun 11 PHP
php中实现精确设置session过期时间的方法
Jul 17 PHP
PHP 获取 ping 时间的实现方法
Sep 29 PHP
PHP simplexml_load_file()函数讲解
Feb 03 PHP
php+Ajax处理xml与json格式数据的方法示例
Mar 04 PHP
在laravel-admin中列表中禁止某行编辑、删除的方法
Oct 03 PHP
php反序列化长度变化尾部字符串逃逸(0CTF-2016-piapiapia)
Feb 15 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 存取 MySQL 数据库的一个例子
2006/10/09 PHP
php数组函数序列之rsort() - 对数组的元素值进行降序排序
2011/11/02 PHP
Zend Framework入门教程之Zend_Session会话操作详解
2016/12/08 PHP
THINKPHP截取中文字符串函数实例代码
2017/03/20 PHP
PHP基于正则批量替换Img中src内容实现获取缩略图的功能示例
2017/06/07 PHP
PHP实现基于图的深度优先遍历输出1,2,3...n的全排列功能
2017/11/10 PHP
PHP给源代码加密的几种方法汇总(推荐)
2018/02/06 PHP
php中的explode()函数实例介绍
2019/01/18 PHP
js滚动条多种样式,推荐
2007/02/05 Javascript
eval与window.eval的差别分析
2011/03/17 Javascript
深入解析contentWindow, contentDocument
2013/07/04 Javascript
js 中将多个逗号替换为一个逗号的代码
2014/06/07 Javascript
Windows系统中安装nodejs图文教程
2015/02/28 NodeJs
Jquery实现顶部弹出框特效
2015/08/08 Javascript
JS实现仿新浪微博发布内容为空时提示功能代码
2015/08/19 Javascript
基于javascript实现随机颜色变化效果
2016/01/14 Javascript
详解vue-router基本使用
2017/04/18 Javascript
webpack 1.x升级过程中的踩坑总结大全
2017/08/09 Javascript
关于TypeScript模块导入的那些事
2018/06/12 Javascript
解决Nuxt使用axios跨域问题
2020/07/06 Javascript
jquery实现简单每周轮换的日历
2020/09/10 jQuery
跟老齐学Python之不要红头文件(1)
2014/09/28 Python
python设计模式大全
2016/06/27 Python
详解python解压压缩包的五种方法
2019/07/05 Python
keras实现调用自己训练的模型,并去掉全连接层
2020/06/09 Python
IE矩阵Matrix滤镜旋转与缩放及如何结合transform
2012/11/29 HTML / CSS
CSS3实现王者荣耀匹配人员加载页面的方法
2019/04/16 HTML / CSS
师范应届毕业生自荐信
2013/11/18 职场文书
俄语专业职业生涯规划
2014/02/26 职场文书
转让协议书范本
2014/04/15 职场文书
植树节口号
2014/06/21 职场文书
党旗在我心中演讲稿
2014/09/15 职场文书
2015年人力资源部工作总结
2015/04/30 职场文书
催款函怎么写
2015/06/24 职场文书
宝宝满月祝酒词
2015/08/10 职场文书
浅谈MySql update会锁定哪些范围的数据
2022/06/25 MySQL