PHP Classes
elePHPant
Icontem

Basic Paginator: Generate HTML links for paginating listings

Recommend this page to a friend!
  Info   View files Documentation   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-04-20 (18 hours ago) RSS 2.0 feedNot enough user ratingsTotal: 206 This week: 13All time: 7,873 This week: 72Up
Version License PHP version Categories
basic-paginator 1.2GNU Lesser Genera...4.1HTML
Description Author

This class can generate HTML links for paginating listings.

It takes as parameters the total number of entries in a listing, the limit of entries to show in each page and the base pagination link URL.

The class can generate a series of HTML links to browse the listing pages or links to go to the next, previous, first, last or any of specific page of the listing.

The name of the URL parameter that defines the current page is configurable.

  Performance   Level  
Name: Roger Baklund <contact>
Classes: 7 packages by
Country: Norway Norway
Innovation award
Innovation award
Nominee: 4x

Details
BasicPagination class

Features:

- Easy to use, multi purpose, easily extendable
- High and low level usage
- Support for multiple languages
- Automatic handling of URL parameters
- Multiple simultaneous paginators 
- Variable width requirements (narrow/wide view)

instantiation:

You must provide the total number of items so that the total number of pages can be calculated.

$P = new BasicPagination($TotalItemCount);                        # specify the total number of items
$P = new BasicPagination($TotalItemCount,'target.php?');          # specify href prefix
$P = new BasicPagination($TotalItemCount,'?',20);                 # 20 items per page (default 10)
$P = new BasicPagination($TotalItemCount,'?',10,'o2');            # alternate offset parameter name
$P = new BasicPagination($TotalItemCount,'?',10,'offset',false);  # non-sticky URL parameters

properties:

All properties can be read and modified directly after instantiation. 
Properties 'link_class' and 'anchor' must be set after instantiation if they are to be used.

$P->max                   # the max offset value, equals $TotalItemCount
$P->baseurl               # prefix for all href attrs, default '?' 
$P->itemcount             # number of items per page, default 10
$P->offset_param_name     # name of URL parameter carrying offset, default 'offset'
$P->offset                # current offset, automatically read from $_REQUEST
$P->sticky                # stickyness of URL parameters, default true
$P->unstick               # array of URL parameter names to NOT use in links
$P->link_class            # class to be added to all links, default '' (none)
$P->anchor                # anchor to append to all links, default '' (none) 

High level methods:

$P->UnStick('foo');       # Drop URL parameter foo when making links
$P->PagesHTML();          # Returns the HTML page links
$P->PagesHTML(40);        # wide screen, up to 40 page links
$P->PagesHTML(12);        # narrow screen, max 12 page links
$P->PagesHTML(12,' - ');  # dash separator

Lower level methods:

$P->pagelinks()                   # returns page links only (not first/last/prev/next)
$P->make_URL($offset)             # returns an URL for use in a HREF or similar
$P->pagelink($page,$Label=false)  # returns a single page link
$P->firstpage()                   # link to the first page
$P->lastpage()                    # link to the last page
$P->nextpage()                    # link to the next page 
$P->prevpage()                    # link to the previous page

Methods meant for overriding:

$P->Label($i)       # Alternative text on page links, see demo
$P->Translate($str) # Implement your translations here, or trough a function named "translate"
$P->PagesHTML()     # Override to change link layout: first - prev - ..... - next - last
  Files folder image Files  
File Role Description
Plain text file BasicPagination.class.php Class Generic class for pagination
Accessible without login Plain text file readme.txt Doc. Class documentation
Accessible without login Plain text file test1_BasicPagination.php Example A basic test/demo script

 Version Control Unique User Downloads Download Rankings  
 0%
Total:206
This week:13
All time:7,873
This week:72Up