fleaphp常用方法分頁(yè)之Pager使用方法
更新時(shí)間:2011年04月23日 20:05:35 作者:
fleaphp常用方法分頁(yè)之Pager使用方法,需要的朋友可以參考下。
Pager 分頁(yè)函數(shù)
/**
* 構(gòu)造函數(shù)
*
* 如果 $source 參數(shù)是一個(gè) TableDataGateway 對(duì)象,則 FLEA_Helper_Pager 會(huì)調(diào)用
* 該 TDG 對(duì)象的 findCount() 和 findAll() 來(lái)確定記錄總數(shù)并返回記錄集。
*
* 如果 $source 參數(shù)是一個(gè)字符串,則假定為 SQL 語(yǔ)句。這時(shí),F(xiàn)LEA_Helper_Pager
* 不會(huì)自動(dòng)調(diào)用計(jì)算各項(xiàng)分頁(yè)參數(shù)。必須通過(guò) setCount() 方法來(lái)設(shè)置作為分頁(yè)計(jì)算
* 基礎(chǔ)的記錄總數(shù)。
*
* 同時(shí),如果 $source 參數(shù)為一個(gè)字符串,則不需要 $conditions 和 $sortby 參數(shù)。
* 而且可以通過(guò) setDBO() 方法設(shè)置要使用的數(shù)據(jù)庫(kù)訪問(wèn)對(duì)象。否則 FLEA_Helper_Pager
* 將嘗試獲取一個(gè)默認(rèn)的數(shù)據(jù)庫(kù)訪問(wèn)對(duì)象。
*
* @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 參數(shù)說(shuō)明
$source 數(shù)據(jù)庫(kù)操作類
$currentPage 當(dāng)前頁(yè)
$pageSize 每頁(yè)顯示記錄數(shù)量
$conditions 查詢條件
$sortby 排序方式
$basePageIndex 頁(yè)碼基數(shù)
Pager 使用示例(實(shí)例)
$dirname = dirname(__FILE__);
define('APP_DIR', $dirname . '/APP');
define('NO_LEGACY_FLEAPHP', true);
require($dirname.'/FleaPHP/FLEA/FLEA.php');
//設(shè)置緩存目錄
FLEA::setAppInf('internalCacheDir',$dirname.'/_Cache');
//鏈接數(shù)據(jù)庫(kù)
$dsn = array(
'driver' => 'mysql',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'wordpress'
);
FLEA::setAppInf('dbDSN',$dsn);
//讀取wp_posts的內(nèi)容
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 返回一些數(shù)據(jù)供調(diào)用
$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,
);
復(fù)制代碼 代碼如下:
/**
* 構(gòu)造函數(shù)
*
* 如果 $source 參數(shù)是一個(gè) TableDataGateway 對(duì)象,則 FLEA_Helper_Pager 會(huì)調(diào)用
* 該 TDG 對(duì)象的 findCount() 和 findAll() 來(lái)確定記錄總數(shù)并返回記錄集。
*
* 如果 $source 參數(shù)是一個(gè)字符串,則假定為 SQL 語(yǔ)句。這時(shí),F(xiàn)LEA_Helper_Pager
* 不會(huì)自動(dòng)調(diào)用計(jì)算各項(xiàng)分頁(yè)參數(shù)。必須通過(guò) setCount() 方法來(lái)設(shè)置作為分頁(yè)計(jì)算
* 基礎(chǔ)的記錄總數(shù)。
*
* 同時(shí),如果 $source 參數(shù)為一個(gè)字符串,則不需要 $conditions 和 $sortby 參數(shù)。
* 而且可以通過(guò) setDBO() 方法設(shè)置要使用的數(shù)據(jù)庫(kù)訪問(wèn)對(duì)象。否則 FLEA_Helper_Pager
* 將嘗試獲取一個(gè)默認(rèn)的數(shù)據(jù)庫(kù)訪問(wèn)對(duì)象。
*
* @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 參數(shù)說(shuō)明
$source 數(shù)據(jù)庫(kù)操作類
$currentPage 當(dāng)前頁(yè)
$pageSize 每頁(yè)顯示記錄數(shù)量
$conditions 查詢條件
$sortby 排序方式
$basePageIndex 頁(yè)碼基數(shù)
Pager 使用示例(實(shí)例)
復(fù)制代碼 代碼如下:
$dirname = dirname(__FILE__);
define('APP_DIR', $dirname . '/APP');
define('NO_LEGACY_FLEAPHP', true);
require($dirname.'/FleaPHP/FLEA/FLEA.php');
//設(shè)置緩存目錄
FLEA::setAppInf('internalCacheDir',$dirname.'/_Cache');
//鏈接數(shù)據(jù)庫(kù)
$dsn = array(
'driver' => 'mysql',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'wordpress'
);
FLEA::setAppInf('dbDSN',$dsn);
//讀取wp_posts的內(nèi)容
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 返回一些數(shù)據(jù)供調(diào)用
復(fù)制代碼 代碼如下:
$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,
);
相關(guān)文章
PHP基于非遞歸算法實(shí)現(xiàn)先序、中序及后序遍歷二叉樹(shù)操作示例
這篇文章主要介紹了PHP基于非遞歸算法實(shí)現(xiàn)先序、中序及后序遍歷二叉樹(shù)操作,結(jié)合實(shí)例形式分析了php采用非遞歸算法對(duì)二叉樹(shù)進(jìn)行先序、中序及后序遍歷操作的原理與具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-01-01基于python發(fā)送郵件的亂碼問(wèn)題的解決辦法
本篇文章小編為大家介紹了,基于python發(fā)送郵件的亂碼問(wèn)題的解決辦法。需要的朋友參考下2013-04-04PHP使用內(nèi)置函數(shù)file_put_contents寫入文件及追加內(nèi)容的方法
這篇文章主要介紹了PHP使用內(nèi)置函數(shù)file_put_contents寫入文件及追加內(nèi)容的方法,結(jié)合實(shí)例形式分析了file_put_contents函數(shù)通過(guò)參數(shù)設(shè)置實(shí)現(xiàn)寫入文件及追加內(nèi)容的相關(guān)技巧,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-12-12PHP下利用header()函數(shù)設(shè)置瀏覽器緩存的代碼
PHP高級(jí)應(yīng)用學(xué)習(xí)筆記之 利用header()函數(shù)設(shè)置瀏覽器緩存2010-09-09PHP連接MySQL數(shù)據(jù)的操作要點(diǎn)
這篇文章主要介紹了PHP連接MySQL數(shù)據(jù)的操作要點(diǎn),本文直接給出代碼實(shí)例,需要的朋友可以參考下2015-03-03php include的妙用,實(shí)現(xiàn)路徑加密
用這種方法比較繁瑣,只能隱藏后臺(tái)腳本的路徑,前端的腳本路徑仍然可以在源文件中看得到(baseref) 在地址欄上看到的地址都是index.php?xxxxxxxx2008-07-07