Fab Pagination: A Zend View Helper for Easy Pagination

What's Fab Pagination?

We love elegant user interfaces, and for that reason, we strive to include the best and easiest pagination possible in a user interface. What's pagination? Well, when you're looking through search results, "pagination" is the links that point you to "Next", "Previous", "First Page", "Last Page", "Page 1 | 2 | 3" and so on.

What's Zend?

We also love the Zend Framework, which enables rapid PHP development for web applications. (It's similar to the very glamorous Ruby On Rails framework, but capitalizes on PHP as an established and flexible web application programming language.)

Description

This pagination view helper only requires three parameters, but is highly configurable beyond that. You have many options at your disposal, including a choice of display formats, choice of page type, customized class names, and customized pagination text. Try Fab Pagination out now by clicking on the "download!" button below!

Download
Version 1.0 - Pagination_1_0.zip

Requirements

Zend Framework 1.0 or greater
PHP 5.1.4 or greater

Installation

1. Extract the tarball
2. Put Pagination.php in the zend view helper directory—usually application/views/helpers/
3. Zend_View should automatically load, instantiate, persist, and execute the helper for you.
4. See the Zend Framework reference guide for further details.

Instructions

In your view script, simply pass the necessary parameters (see "Parameters" below) through the pagination() method. For example:

<?php
$page = 1;
$perPageCount = 25;
$totalCount = 491;
$pagination = this->pagination($page, $perPageCount, $totalCount);
echo $pagination;
?>

However, we suggest that when using Zend Framework's MVC system, calculate the parameters and assign them to the view object within the action controller, not within the view script itself—using $this->view->[parameter]

<?php
$pagination = $this->pagination($this->page, $this->perPageCount, $this->totalCount);
echo $pagination;
?>

Parameters

Parameter Type Req? Description Default
1. $page integer yes The current page number. [none]
2. $perPageCount integer yes The number of results per page. [none]
3. $totalCount integer yes The total number of results. [none]
4. $pageName string|
boolean
no The name of the page identifier. Set this to false when the page name is not in the URL query string. 'page'
5. $url string no The URL of subsequent page (absolute or relative). $_SERVER['PHP_SELF']
6. $queryArray array no An associative array containing form data you want to pass to subsequent pages. Most of the time this is the $_GET superglobal. Use only when a traditional URL query string is necessary to pass variables. $_GET
7. $pagesType array no An associative array containing pages type as key and number as value.
Option 1: array('show'=>[number]): this number of pages will display at all times.
Option 2: array('pad'=>[number]): this number of pages will pad to each side of the current page.
array('show'=>10)
8. $displayFormat integer no The number that signifies the display format of the pagination, following this component list: first/previous/pages/next/last.
1: display all components, even unlinked ones
2: display only active components, i.e. only when f/p/n/l are needed
3: display all components except pages
4: display only active components except pages
5: display only pages, i.e. do not display f/p/n/l
1
9. $classes array no An associative array containing class names. May contain the following keys: pagination/first/ firstGhost/previous/ previousGhost/ellipsis/ currentPage/pages/ next/nextGhost/ last/lastGhost array(
'pagination'=>
'pagination',
'first'=>
'paginationFirst',
'firstGhost'=>
'paginationFirstGhost',
...
)
10. $texts array no And associative array containing pagination texts. May contain the following keys: first/previous/ ellipsis/next/last. array(
'first'=>
'&#171;&#171;first', 'previous'=>
'&#171;previous', 'ellipsis'=>
'&#8230;',
...
)

License

GPL License
Fab Pagination by Fab Apps is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.