Pear: Pager paging class introduction. 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, there is no paging amount
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:
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 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:
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
...