Pagination Class

CodeIgniter's Pagination class is very easy to use, and it is 100% customizable, either dynamically or via stored preferences.
If you are not familiar with the term "pagination", it refers to links that allows you to navigate from page to page, like this:

« First  < 1 2 3 4 5 >    Last 

 functions:
$this->load->library('pagination');

$config['base_url'] = 'http://example.com/index.php/test/page/';


$config['total_rows'] = 200;
$config['per_page'] = 20;

$this->pagination->initialize($config);

echo $this->pagination->create_links();


Customizing the Pagination

The following is a list of all the preferences you can pass to the initialization function to tailor the display.

$config['uri_segment'] = 3;

The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.

$config['num_links'] = 2;

The number of "digit" links you would like before and after the selected page number. For example, the number 2 will place two digits on either side, as in the example links at the very top of this page.

$config['use_page_numbers'] = TRUE;

By default, the URI segment will use the starting index for the items you are paginating. If you prefer to show the the actual page number, set this to TRUE.

$config['page_query_string'] = TRUE;

By default, the pagination library assume you are using URI Segments, and constructs your links something like

http://example.com/index.php/test/page/20

If you have $config['enable_query_strings'] set to TRUE your links will automatically be re-written using Query Strings. This option can also be explictly set. Using $config['page_query_string'] set to TRUE, the pagination link will become.

http://example.com/index.php?c=test&m=page&per_page=20

Note that "per_page" is the default query string passed, however can be configured using $config['query_string_segment'] = 'your_string'