Pager Paging function
Copy Code code as follows:
/**
* Constructor
*
* If the $source parameter is a Tabledatagateway object, Flea_helper_pager calls the
* The Findcount () and FindAll () of the TDG object determine the total number of records and return the recordset.
*
* If the $source parameter is a string, it is assumed to be an SQL statement. At this time, Flea_helper_pager
* The calculation of each paging parameter is not automatically invoked. The SetCount () method must be used to set as a paging calculation
* The total number of records on the basis.
*
* At the same time, if the $source parameter is a string, no $conditions and $sortby parameters are required.
* and you can set the database Access object to use by using the Setdbo () method. otherwise Flea_helper_pager
* Will attempt to get 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 =, $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 parameter Description
$source Database Operations Class
$currentPage Current Page
$pageSize display the number of records per page
$conditions Query criteria
How to $sortby sort
$basePageIndex Page Number Base
Pager Use Example (instance)
Copy Code code as follows:
$dirname = DirName (__file__);
Define (' App_dir ', $dirname. '/app ');
Define (' no_legacy_fleaphp ', true);
Require ($dirname. ' /fleaphp/flea/flea.php ');
Set Cache Directory
Flea::setappinf (' Internalcachedir ', $dirname. /_cache ');
Link Database
$DSN = Array (
' Driver ' => ' MySQL ',
' Host ' => ' localhost ',
' Login ' => ' root ',
' Password ' => ',
' Database ' => ' WordPress '
);
Flea::setappinf (' DbDSN ', $DSN);
Read the contents of the 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 returns some data for call
Copy Code code as follows:
$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,
);