The Pager usage method of fleaphp. The code for copying Pager paging functions is as follows: ** constructor ** if the $ source parameter is a TableDataGateway object, FLEA_Helper_Pager calls the * fin Pager paging function of the TDG object.
The code is as follows:
/**
* Constructor
*
* If the $ source parameter is a TableDataGateway object, FLEA_Helper_Pager calls
* The findCount () and findAll () of the TDG object are used to determine the total number of records and return the record set.
*
* If the $ source parameter is a string, it is assumed to be an SQL statement. In this case, FLEA_Helper_Pager
* The calculated paging parameters are not automatically called. The setCount () method must be used for paging calculation.
* Total number of basic records.
*
* If the $ source parameter is a string, the $ conditions and $ sortby parameters are not required.
* You can use the setDBO () method to set the database access object to be used. Otherwise, FLEA_Helper_Pager
* A default database access object will be obtained.
*
* @ 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 parameter description
$ Source database operations
$ CurrentPage current page
$ PageSize: number of records displayed per page
$ Conditions query conditions
$ Sortby sorting method
$ BasePageIndex page number base
Example of Pager usage (instance)
The code is as follows:
$ Dirname = dirname (_ FILE __);
Define ('app _ dir', $ dirname. '/app ');
Define ('no _ LEGACY_FLEAPHP ', true );
Require ($ dirname. '/FleaPHP/FLEA. php ');
// Set the cache Directory
FLEA: setAppInf ('internalcachedir', $ dirname. '/_ cache ');
// Link to the database
$ Dsn = array (
'Driver '=> 'mysql ',
'Host' => 'localhost ',
'Login' => 'root ',
'Password' => '',
'Database' => 'wordpress'
);
FLEA: setAppInf ('dbdsn ', $ dsn );
// Read wp_posts content
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 calling.
The 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,
);
The code for the http://www.bkjia.com/PHPjc/323267.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323267.htmlTechArticlePager paging function is as follows:/*** constructor *** if the $ source parameter is a TableDataGateway object, FLEA_Helper_Pager will call * fin of the TDG object...