Pear: Introduction to:P Ager Page class _php tutorial

Source: Internet
Author: User

Pear Pager Page class is a very useful PHP paging class, extensibility is very strong, able to adapt to the needs of various paging situation, at least I have a few years of large and small projects, basically no extra code for pagination, all are used pager, This is the pager of usability. The following code looks at its use 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 a ordered+associative array with back/pages/next/first/last/all links
NB: $links [all] are 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:;p rint_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);
?>
The use of pager, as long as the parameters of the $param array can be adjusted to 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 pagination still has the means to work, see the code below

PLAIN TEXT
Php:
require_oncepager/pager.php;

First 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, it is possible to link "/articles/march/art15.html" to the link "/article.php?num=15&month=march" for more flexible performance

Scalability
Pager class extensibility, in all fairness, is also good. For example, the previously written page class of path mode-Pager::P athing (), this method is extended from the Pager to meet the needs of the time.

Author: Volcano published in September, 2006 at 7:16 am

Copyright information: Can be reproduced in any way, please be sure to use hyperlinks in the form of the original source of the article and the author's information and this statement

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

http://www.bkjia.com/PHPjc/486639.html www.bkjia.com true http://www.bkjia.com/PHPjc/486639.html techarticle Pear Pager Page class is a very useful PHP paging class, extensibility is very strong, able to adapt to the needs of various paging situations, at least I have a few years of large and small projects, basically no paging amount ...

  • Related Article

    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.