This library provides a clean, decoupled "API" for developers to integrate pagination markup into their site or application.
It provides simple methods to control the settings for the generated pagination markup, including the number of items per page, the total number of items and more.
Well, that's a good question. There are plenty of pagination scripts out there, but they all felt increasingly complicated for what I was trying to do. I wanted a library that decoupled it's processing logic from the view that would be rendered for the pagination markup.
One where you could define an instance of the
Pagination class, define it's
properties programmatically, and have the rendered markup use the object to
generate clean, semantic, valid markup.
This library contains two files:
PaginationInstantiable class for pagination objects/settings
render.inc.phpView which generates the pagination markup
The relevant public methods for a
Pagination instance are:
parseReturns a string of the generated pagination markup
setCrumbsSets the pagination to exclude page numbers, and only output preview/next markup. The counter-method of this is the
setCurrentSets the maximum number of 'crumbs' (eg. numerical page items) that are shown
setCrumbsSets the current page being viewed
setFullSets the pagination to include numbers (counter-method of
setKeySets the key of the
_GETarray that contains, and ought to contain, paging information (eg. which page is being viewed)
setNextSets the copy of the next anchor
setPreviousSets the copy of the previous anchor
setRPPSets the number of records per page (used for determining total number of pages)
setTargetSets the leading path for anchors
setTotalSets the total number of records available for pagination
Using the Pagination library requires only a few lines of PHP, which will take you to a point whereby you have a variable that contains valid markup for your pagination list items/links.
This markup will not, however, be styled.. at all. For this, you'll have to use
light.css stylesheet. Moving it over to your webroot/static
folder and including it should do the trick.
Hopefully over time, I'll be able to add some more themes :)
I'm starting to question the efficacy and information that this section can offer. Anyway.
I abstracted this library out in the way that I did, because I wanted the application and view logic to be independent of one another.
I've seen pagination libraries before where a PHP class will generate markup inside of a massively-escaped method/function. I found this to be pretty inefficient, and made reading the view logic really difficult. Not to mention how difficult it was to make changes to the markup that would be generated.
This is a library that can be used independently from any framework.
Yup. Next up, PHP-MySQL.
I've updated the library in order for it to be compatible with Twitter Bootstrap. I've made the following changes:
disabledclass from the anchor level to the list-item level
setClasses) to allow you to specify UI-classes for the top-level pagination div (eg. adding the