服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - PHP教程 - fleaphp常用方法分页之Pager使用方法

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

2019-11-22 12:53PHP教程网 PHP教程

fleaphp常用方法分页之Pager使用方法,需要的朋友可以参考下。

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教程批量修改RAR文件注释的php代码

    批量修改RAR文件注释的php代码

    下面的代码就是我通过我的数据库读取出文件路径并最终实现批量修改RAR文件注释的方法.因为数据库是ACCESS,我新建了一个ODBC源.同时RAR.exe及CMD.EXE都在1.P...

    php代码网2512019-11-12
  • PHP教程PHP设计模式之状态模式定义与用法详解

    PHP设计模式之状态模式定义与用法详解

    这篇文章主要介绍了PHP设计模式之状态模式定义与用法,结合实例形式分析了php状态模式的概念、原理、定义、使用方法及相关注意事项,需要的朋友可以参...

    雪山飞猪3322019-10-14
  • PHP教程php删除二维数组中的重复值方法

    php删除二维数组中的重复值方法

    下面小编就为大家分享一篇php删除二维数组中的重复值方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧 ...

    pengmingdong2552019-10-18
  • PHP教程PHP实时统计中文字数和区别

    PHP实时统计中文字数和区别

    今天小编就为大家分享一篇关于PHP统计实时统计汉字个数和区别,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小...

    chajinglong2342019-06-09
  • PHP教程PHP htmlentities()函数用法讲解

    PHP htmlentities()函数用法讲解

    今天小编就为大家分享一篇关于PHP htmlentities()函数用法讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来...

    php参考手册4892019-06-10
  • PHP教程php JWT在web端中的使用方法教程

    php JWT在web端中的使用方法教程

    这篇文章主要给大家介绍了关于php JWT在web端中的使用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋...

    soledad2572019-09-08
  • PHP教程PHP上传文件及图片到七牛的方法

    PHP上传文件及图片到七牛的方法

    这篇文章主要介绍了PHP上传文件及图片到七牛的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧 ...

    PMPSSPMP3102019-09-18
  • PHP教程laravel中的一些简单实用功能

    laravel中的一些简单实用功能

    这篇文章主要给大家介绍了关于laravel中一些简单实用功能的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值...

    gaoziyuecj4412019-08-30