Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter pagination url page number

From what I saw, CodeIgniter's pagination is counting the page wrong way, because I got pagination looking like this:

1 2 3 >

And its good, the problem is in the each pagination number url, except the first one:

Number 2 from the pagination has the following url:

http://my-url.com/index.php/page/1

And number 3 has the following url:

http://my-url.com/index.php/page/2

So, the number is URL is decreased by 1 everytime.

How can I solve that, so the page numbers in urls will be the same as the page numbers in the pagination?

My pagination config:

$config['per_page']    = 5;
$config['base_url']    = site_url('page');
$config['uri_segment'] = 2;
$page = $this->uri->segment(2);
$total_rows_array = $this->records->get($config['per_page'], $page * $config['per_page']); // parameters: limit, offset.
$config['total_rows']  = count($total_rows_array);
like image 597
Lucas Avatar asked Dec 01 '22 00:12

Lucas


1 Answers

Had the same problem you have, and I added this configuration line:

$config['use_page_numbers'] = TRUE;

and it works like a charm!

like image 123
Francisco Ochoa Avatar answered Dec 04 '22 02:12

Francisco Ochoa