fleaphp常用方法分页之Pager使用方法
作者:bea
Pager 分页函数 代码如下: /** * 构造函数 * * 如果 $source 参数是一个 TableDataGateway 对象,则 FLEA_Helper_Pager 会调用 * 该 TDG 对象的 findCount() 和 findAll() 来确定记录总数并返回记录集。 * * 如果 $source 参数是一个字符串,则假定为 SQL 语句。这时,FLEA_Helper_Pager * 不会自动调用计算各项分页参数。必须通过 setCoun
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,
);
有用 | 无用
代码如下:
/**
* 构造函数
*
* 如果 $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操作MongoDB时的整数问题及对策说明
- php HandlerSocket的使用
- 深入理解PHP原理之错误抑制与内嵌HTML分析
- PHP错误抑制符(@)导致引用传参失败Bug的分析
- 一些PHP Coding Tips(php小技巧)[2011/04/02最后更新]
- PHP中使用gettext来支持多语言的方法
- php中神奇的fastcgi_finish_request
- PHP 调试工具Debug Tools
- php debug 安装技巧
- vs中通过剪切板循环来循环粘贴不同内容
- php获取mysql数据库中的所有表名的代码
- 使用GROUP BY的时候如何统计记录条数 COUNT(*) DISTINCT
- mysql_num_rows VS COUNT 效率问题分析
- fleaphp rolesNameField bug解决方法
- FirePHP 推荐一款PHP调试工具
- 在smarty模板中使用PHP函数的方法
- 对text数据类型不支持代码页转换 从: 1252 到: 936
- fleaphp crud操作之find函数的使用方法
- fleaphp crud操作之findByField函数的使用方法