Pear: Pager paging class Introduction

Source: Internet
Author: User
Tags pear

Pear's Pager paging class is a very useful php paging class, which is highly scalable and can meet the requirements of various paging situations. At least I have been working on projects large and small in a few years, basically, no additional code has been written for pagination, and all of them use Pager, which is highly available. the following code is used to see its usage example:

Example 1
PLAIN TEXT
PHP:
<? 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 <link rel = "first | prev | next | last"> 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 only need to adjust the parameters of the $ param array to cope with many paging situations. the $ links array in the Code contains links, such as the previous page, page number, next page, first page, last page, and all.

Example 2
Today, many websites use rewrite rules to forge dynamic pages into static pages for SEO. For example, the following. htaccess Configuration:

RewriteEngine on
# Options FollowSymlinks

RewriteBase/
RewriteRule ^ articles/([a-z] {})/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:
<? 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 map the link "/articles/march/art15.html" to the link "/article. php? Num = 15 & month = march ", more flexible performance

Scalability
The scalability of the Pager class is also good in all fairness. for example, in the previously written path paging class-Pager: Pathing (), this method is extended from Pager to meet the current needs.

Published by volcano on September 16, 2006 at am

Copyright information: this information can be reproduced at will. During reprinting, you must mark the original source and author information of the article in the form of hyperlinks and this statement.

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

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.