Fleaphp Common Methods Pager use method _php skill of paging

Source: Internet
Author: User
Tags dsn
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,
);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.