Welcome Guest, Not a member yet? Register   Sign In
Generic Pagination Class
#1

[eluser]theprodigy[/eluser]
I've written a generic paginate class. It can be used as a CI custom Library or in non-CI applications (as it does not contain any CI specific functionality)

It functions very similarly to CI's paginate class with one main difference.

I didn't like the fact with CI's pagination class that if you had 10 pages and set the number of links to 2 (2 before and 2 after), but were on page 1, it only showed 3 links, and if you were on page 2, it would show 4 links, and from then on out to page 8, it would show the 5 links you requested. Then it would go back to 4 links on page 9, and 3 links on page 10 ( it through my php ocd into overdrive, lol ).

My class asks for the number of pages you want shown, not the number of links before/after.

My class allows you to set things via a generic config function (with an assoc array as a parameter), or individual setter methods (each method has it's own set of parameters, see documented code for specifics).

The things you can set are:
Code:
$first_link_text;
$last_link_text;
$previous_link_text;
$next_link_text;
$replacement_text;
$pagination_href;
$total_items;
$items_per_page;
$current_page;
$number_of_pages;
$first_link_wrap_tags;
$last_link_wrap_tags;
$previous_link_wrap_tags;
$next_link_wrap_tags;
$numeric_link_wrap_tags;
$current_page_wrap_tags;

All items have default values, so you can choose to only set a few or all.

Also, this pagination class takes page numbers not record offset numbers.

What is returned is an array:
Code:
array(
     first => entire anchor tag for the first link
     last  => entire anchor tag for the last link
     prev  => entire anchor tag for the previous link
     next  => entire anchor tag for the next link
     pages => string containing multiple anchor tags for the individual pages, and the current page non-link.
     )

The code, I believe, is very well documented. I tried having a couple people alpha test it, but I have yet to hear any response.

You can download it here: Paginate Class

Please let me know what you think of this class, whether good or bad. I would love to hear your input.
#2

[eluser]Mark Croxton[/eluser]
This looks great! The varying number of pages shown by CIs class bothers me too. And I like that it returns an array, that's much easier to work with.
#3

[eluser]theprodigy[/eluser]
I added the ability to change the page link separator.
This is what is in between each numeric page link. It will not be between First, Prev, Next, or Last (unless you put it in yourself ;-) )

The variable name is $page_link_separator (for use in config array)
The public setter is set_page_link_separator( $link_sep )

The page link separator can be set to anything.
Commonly used are:
Code:
 
Code:
•
and combination of the two
Code:
 • 

The default is set to non-breaking space.

Since I have not yet provided an example of use, here are two examples (one using config array, and one using public setters)

Example 1 (config array):
Code:
// Load the library
$this->load->library('paginate');

// Setup config array
$config = array(
        'total_items' => 100,
        'items_per_page' => 20,
        'current_page' => 1,
        'page_link_separator' => '•'
    );

// Pass in config array to library
$this->paginate->configure($config);

// Get the pagination array
$this->data['pages'] = $this->paginate->get();

Example 2 (public setters) setting same items:
Code:
// Load the library
$this->load->library('paginate');

// Set the elements
$this->paginate->set_total_items(100);
$this->paginate->set_items_per_page(20);
$this->paginate->set_current_page(1);
$this->paginate->set_page_link_separator('•');

// Get the pagination array
$this->data['pages'] = $this->paginate->get();




Theme © iAndrew 2016 - Forum software by © MyBB