Pager | Pager "Jumping" vs. "Sliding" |
Pager | |
PEAR Manual | |
Pager is a class to page an array of data. It is taken as input and it is paged according to various parameters. Pager also builds links within a specified range, and allows complete customization of the output (it even works with mod_rewrite). It is compatible with Pager v.1.x and Pager_Sliding API
This simple example will page the array of alphabetical letters, giving back pages with 3 letters per page, and links to the previous two / next two pages:
|
This example shows how you can use this class with mod_rewite. Let's suppose we have a .htaccess like this:
--------- RewriteEngine on #Options FollowSymlinks RewriteBase / RewriteRule ^articles/([a-z]{1,12})/art([0-9]{1,4})\.html$ /article.php?num=$2&month=$1 [L] --------- |
|
Using more than one pager in a single page is as simple as using a different urlVar for each pager:
|
If you want to paginate db resultsets, fetching them all into an array and passing it to Pager might not be the best option. You can still leverage Pager and have good performances using a wrapper. There is a sample wrapper for each one of the PEAR db abstraction systems in the /docs/examples/ dir of the package. You may use it as-is or customize it to your needs.
If you need to add some extra variables to the querystring, use the extraVars parameter:
|
Since version 2.2.1, Pager works with PHP 5 too, but you must use the factory() method instead of the constructor (which is deprecated):
|
If you are using a previous revision and cannot update, you must write the following code on PHP 5:
|
There are some other online resources with in-depth coverage of what Pager can do: PEAR::Pager tutorials.
Pager | Pager "Jumping" vs. "Sliding" |
Pager | |
PEAR Manual | |