0
votes

using the default pagination class, and following the odeigniter user manual i fail to see how you can make the url make sense to the user?

for example: the links will look like this: < 1 2 3 4 5 > but the url for link 1 is

localhost/entries/page/

when i would expect it to be

localhost/entries/page/1

similarly on page 3 it is:

localhost/entries/page/4

obviously it is using the offset as the 3rd segment in the uri. How can I get pagination to work using page numbers, where the link numbers actually match the 3rd uri segment?

1

1 Answers

2
votes

You can easily set in the config for the pagination class:

Taken from the docs:

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.

So:

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

$config['base_url'] = //site_url('controller/method');
$config['total_rows'] = //get rows from model
$config['per_page'] = 10; 
$config['use_page_numbers'] = TRUE;

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

Extra tip: note that if your uri segment is not the 3rd (default) you can also set which one to use (I once risked my mental sanity for this):

$config['uri_segment'] = 4;