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,
);
http://www.bkjia.com/PHPjc/323267.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323267.htmlTechArticlePager 分頁函數 複製代碼 代碼如下: /** * 建構函式 * * 如果 $source 參數是一個 TableDataGateway 對象,則 FLEA_Helper_Pager 會調用 * 該 TDG 對象的 fin...