Pear: Introduction to the:P Ager page class

Source: Internet
Author: User
Tags pear

Pear's pager pagination class is a very useful PHP paging class, scalability is very strong, able to adapt to the needs of various paging situation, at least I in a few years large and small projects, basically not for paging extra code, all are used pager, It shows the pager of the availability of the strong. Here's how to use the code to see the example:

Example 1

<?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 a ordered+associative array with ' back '/' pages '/' Next '/' I '/' 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);
?>

The use of pager, as long as you adjust the parameters of the $param array, you can cope with many kinds of paging situation. The $links array in the code contains links such as previous/page/next/First/last/all.

Example 2

Today many web sites for SEO, the dynamic page using rewrite rules forged into a static page form, 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 following code

<?php
Require_once ' pager/pager.php ';
The pager
$params 1 = Array (
' Perpage ' => 3,
' Urlvar ' => pageid_articles, //1st identifier
' ItemData ' => $someArray
);
$pager 1 = & Pager::factory ($params 1);
$data 1 = $pager 1->getpagedata ();
$links 1 = $pager 1->getlinks ();
Second Pager
$params 2 = Array (
' Perpage ' => 8,
' Urlvar ' => pageid_news, //2nd identifier
' ItemData ' => $someOtherArray
);
$pager 2 = & Pager::factory ($params 2);
$data 2 = $pager 2->getpagedata ();
$links 2 = $pager 2->getlinks ();
?>

By configuring $param, you can link "/articles/march/art15.html" to the link "/article.php?num=15&month=march", more flexible performance

Extensibility

The extensibility of the Pager class, in all fairness, is also good. such as the previously written path of the paging class-Pager::P athing (), this method is extended from the Pager to meet the needs of the time.

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.