Plugin: Paging Simplified

Paging Simplified is an alternative paging class that is easier to use than CodeIgniter’s default paging library.

  • Extremely lightweight
  • Very easy to configure and use
  • Won’t tear up your URI string
  • GET query strings not supported
  • PHP5-only

Installation

Just download and extract paging_pi.zip (source) into your application/plugins folder. I made this a plugin so I could us it as a static class rather than having it attached to $this.

Link format

Links are in this format:

http://mysite.com/controller/function/…[segments]…/pg:1/…[segments]…

The segment containing the current page number can vary (there can be additional segments before or after). Paging Simplified will automatically parse the segments and find the id (“pg” in the above example) that you pass to the Paging::init() function.

Here’s another example:

http://mysite.com/controller/function/segment/pg:5/segment/segment

Example Controller Code

$this->load->plugin('paging');$query = $this->db->get('items');
$item_count = $query->num_rows();

// total number of items, items per page, page segment id
Page::init($item_count, 25, 'pg');

// generate the page links
$this->data['paging'] = Page::page_links();

// get the items to show in the current page
$this->data['items'] = $this->db->limit(Page::$perpage, Page::$offset)->get('items')->result();

// show the view
$this->load->view('items_view', $this->data);

Customizing the page links

Paging Simplified will automatically use the tag configuration in your pagination.php config file if it is present. For more information on the tag configuration options, see the CodeIgniter User Guide.

One thought on “Plugin: Paging Simplified”

  1. i guess there are small bugs in your codes.

    line 130:
    return preg_match($regex, self::$script_url)? preg_replace($regex, self::$key.':’.$page, self::$script_url) : rtrim(self::$script_url, ‘/’).’/pg:’.$page;

    should be:
    return preg_match($regex, self::$script_url)? preg_replace($regex, self::$key.':’.$page, self::$script_url) : rtrim(self::$script_url, ‘/’).’/’.self::$key.':’.$page;

    line 56:
    list($pg, $num) = explode(‘:’, $segment);

    could be:
    @list($pg, $num) = explode(‘:’, $segment);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Hello! I’m a self-taught freelance web developer, and this is my blog. Here, I document problems and solutions in PHP, MySQL, and Javascript that I encounter along the way. Enjoy!