Introduction

Introduction – Usage of Pager 2.x

What is Pager?

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

Example 1

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:

In case you're wondering, $pager->range is a numeric array; its keys are the numbers of
the pages in the current range, and the matching values are booleans (TRUE if its key
represents currentPage, FALSE otherwise). This array can be useful to build the links
manually, e.g. when using a template engine.

Example 2

This example shows how you can use this class with mod_rewite.
Let's suppose we have a .htaccess like this:

Pager and big db resultsets

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.

Adding extra variables to the querystring

If you need to add some extra variables to the querystring,
use the extraVars
parameter: