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 have basically not written additional code for paging. , all use Pager, which shows the strong usability of Pager. Let’s use the code to see its usage examples:
Example 1
PLAIN TEXT
PHP:
<?php
require_once'Pager/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 <link rel="first|prev|next|last"> tags
echo$pager->linkTags;
//Show data for current page:
echo'PAGED DATA: ';print_r($data);
//Results from methods:
echo'getCurrentPageID()...: ';var_dump($pager->getCurrentPageID());
echo'getNextPageID()......: ';var_dump($pager->getNextPageID());
echo'getPreviousPageID()..: ';var_dump($pager->getPreviousPageID());
echo'numItems().....: ';var_dump($pager->numItems());
echo'numPages().....: ';var_dump($pager->numPages());
echo'isFirstPage().....: ';var_dump($pager->isFirstPage());
echo'isLastPage()..........: ';var_dump($pager->isLastPage());
echo'isLastPageComplete().: ';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, many websites use rewrite rules to fake dynamic pages into static pages for the sake of SEO, such as the following .htaccess configuration:
RewriteEngine on
#Options FollowSymlinks
RewriteBase /
RewriteRule ^articles/([az]{1,12})/art([0-9]{1,4}).html$ /article.php?num=$2&month=$1 [L]
Even in this In this case, Pager paging still has a way to work, see the code below
PLAIN TEXT
PHP:
<?php
require_once'Pager/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 map the link "/articles/march/art15.html" to the link "/article.php?num=15&month=march", which shows more flexible
scalability.
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 met the needs at the time.
Author: volcano Published in 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
the permanent link of this statement in the form of a hyperlink - http://www.ooso.net/index. php/archives/250