Pager Paging function
Copy CodeThe code is as follows:
/**
* Constructor function
*
* If the $source parameter is a Tabledatagateway object, Flea_helper_pager will call 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
* Calculation of each paging parameter is not automatically called. Must be set as a paging calculation by using the SetCount () method
* The total number of records underlying.
*
* At the same time, $conditions and $sortby parameters are not required if the $source parameter is a string.
* and you can set the database Access object to use through 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 Classes
$currentPage Current Page
$pageSize show the number of records per page
$conditions Query criteria
$sortby Sorting methods
$basePageIndex Page Number Cardinality
Pager using Example (instance)
Copy CodeThe code is as follows:
$dirname = DirName (__file__);
Define (' App_dir ', $dirname. '/app ');
Define (' no_legacy_fleaphp ', true);
Require ($dirname. ' /fleaphp/flea/flea.php ');
Set the 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 invocation
Copy CodeThe code is 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,
);
http://www.bkjia.com/PHPjc/323267.html www.bkjia.com true http://www.bkjia.com/PHPjc/323267.html techarticle Pager page function copy the code code as follows:/** * constructor * * If the $source parameter is a Tabledatagateway object, Flea_helper_pager calls the TDG of the fin...