fleaphp常用办法分页之Pager使用办法

家电修理 2023-07-16 19:17www.caominkang.com电器维修

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->putingPage();
} 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->putingPage();
}
}

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',
'passord' => '',
'database' => 'ordpress'
);
FLEA::setAppInf('dbDSN',$dsn);
//读取p_posts的内容
FLEA::loadClass('FLEA_Db_TableDataGateay');
FLEA::loadClass('FLEA_Helper_Pager');
//FLEA::loadHelper('pager');
class Teble_Class extends FLEA_Db_TableDataGateay {
var $tableName = 'p_posts';
var $primaryKey = 'ID';
}
$tableposts =& ne Teble_Class();
$pager =& ne 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,
);

Copyright © 2016-2025 www.caominkang.com 曹敏电脑维修网 版权所有 Power by