Home  >  Article  >  Backend Development  >  Common methods of paging in fleaphp: How to use Pager_PHP tutorial

Common methods of paging in fleaphp: How to use Pager_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:30:041121browse

Pager 分页函数

复制代码 代码如下:

/**
* Constructor
*
* If the $source parameter is a TableDataGateway object, FLEA_Helper_Pager will call
* findCount() and findAll() of the TDG object to determine the total number of records and return the recordset .
*
* If the $source parameter is a string, a SQL statement is assumed. At this time, FLEA_Helper_Pager
* will not automatically call to calculate various paging parameters. The total number of records used as the basis for paging calculations
* must be set via the setCount() method.
*
* At the same time, if the $source parameter is a string, the $conditions and $sortby parameters are not required.
* And the database access object to be used can be set through the setDBO() method. Otherwise FLEA_Helper_Pager
* will try to obtain a default database access object.
*
* @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,
);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323267.htmlTechArticlePager paging function copy code code is as follows: /** * Constructor* * If the $source parameter is a TableDataGateway object , then FLEA_Helper_Pager will call * the fin of the TDG object...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn