Home > Backend Development > PHP Tutorial > Introduction to Pear::Pager paging class_PHP tutorial

Introduction to Pear::Pager paging class_PHP tutorial

WBOY
Release: 2016-07-13 17:36:43
Original
968 people have browsed it

Pear's Pager paging class is a very useful PHP paging class. It is highly scalable and can adapt to the needs of various paging situations. At least in my large and small projects over the past few years, I basically have no I have written additional code for paging, all of which use Pager, which shows the strong usability of Pager. Let’s use the code to see its usage example:

Example 1
PLAIN TEXT
PHP:
require_oncePager/Pager.php;
$params=array(
mode =>Jumping,
perPage =>3,
delta =>2,
itemData =>array(a,b,c,d,e,[...omissis...],z)
);
$pager= & Pager::factory($params);
$data =$pager->getPageData();
$links=$pager->getLinks();
//$links is an ordered+associative array with back/pages/next/first/last/all links
//NB: $links[all] is the same as $pager->links;

//echo links to other pages:
echo$links[all];

//Pager can also generate tags
echo$pager->linkTags;

//Show data for current page:
echoPAGED DATA: ;print_r($data);

//Results from methods:
echogetCurrentPageID()...: ;var_dump($pager->getCurrentPageID());
echogetNextPageID()...: ;var_dump($pager->getNextPageID());
echogetPreviousPageID()..: ;var_dump($pager->getPreviousPageID());
echonumItems().....: ;var_dump($pager->numItems() );
echonumPages().............: ;var_dump($pager->numPages());
echoisFirstPage().....: ;var_dump ($pager->isFirstPage());
echoisLastPage().........: ;var_dump($pager->isLastPage());
echoisLastPageComplete().: ;var_dump ($pager->isLastPageComplete());
echo $pager->range.....: ;var_dump($pager->range);
?>
When using Pager, you can handle many paging situations by adjusting the parameters of the $param array. The $links array in the code contains some links, such as previous page/page number/next page/first page/last page/all .

Example 2
Nowadays, for the sake of SEO, many websites use rewrite rules to fake dynamic pages into static pages, such as the following .htaccess configuration:

RewriteEngine on
#Options FollowSymlinks

RewriteBase /
RewriteRule ^articles/([a-z]{1,12})/art([0-9]{1,4}).html$ /article.php?num=$2&month=$1 [L]

Even in this case, Pager paging still has a way to work, see the code below

PLAIN TEXT
PHP:
require_oncePager/Pager.php;

//first pager
$params1=array(
perPage => ;3,
urlVar => pageID_articles, //1st identifier
itemData =>$someArray
);
$pager1= & Pager::factory($params1);
$ data1 =$pager1->getPageData();
$links1=$pager1->getLinks();

//second pager
$params2=array(
perPage => ;8,
urlVar => pageID_news, //2nd identifier
itemData =>$someOtherArray
);
$pager2= & Pager::factory($params2);
$ data2 =$pager2->getPageData();
$links2=$pager2->getLinks();
?>
By configuring $param, you can put the link "/articles/march/ art15.html "corresponds to the link "/article.php?num=15&month=march", more flexible performance

Extensibility
To be fair, the scalability of the Pager class is also good. For example, the previously written path-based paging class - Pager::Pathing(), this method was extended from Pager and satisfied the needs at the time. needs.

Author: volcano Published on September 22, 2006 at 7:16 am

Copyright information: You can reprint at will. When reprinting, please be sure to indicate the original source and author information of the article and this statement in the form of a hyperlink

Permanent link - http://www.ooso.net/index.php/archives/250

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486639.htmlTechArticlePear’s Pager paging class is a very useful PHP paging class. It is highly scalable and can adapt to various Regarding the need for paging, at least in my large and small projects over the past few years, I have basically not paid for paging...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template