Fleaphp Common Methods Pager use method _php Tutorial

Source: Internet
Author: User
Tags dsn
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...

  • 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.