Reputation: 754
I have a route in my config/routes file as follows:
$route['thing/(:num)'] = 'site/pages/$1';
And in my pagination config which is in site/pages
, there are the following related options:
$config["base_url"] = base_url() . "thing";
$config["uri_segment"] = 3;
The above generates links correctly, as: thing/20, thing/40 (as I've given 20 per page config option) And the first page displays correctly with 20 links.
But when I click on the second page link, it returns a 404. When I go ahead and edit the url in the browser to /site/pages/20 or site/pages/40, it works.
What am I doing wrong here?
Upvotes: 0
Views: 3944
Reputation: 4305
If you are looking for any reference how to do pagination and at the same time with good routing to each page link please look into this Pagination reference answer given by me for one of the question. I hope it will clear all your doubts.
Upvotes: 0
Reputation: 16
Try to use
$config["base_url"] = base_url("thing/");
$config["uri_segment"] = 2;
remember that uri segment is refered to the uri
Upvotes: 0
Reputation: 102745
You actually want to read the routed URI segment (the one that is actually in the URL). Because of your routing configuration, it would be the second segment:
$config["uri_segment"] = 2;
From the docs:
The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.
The pagination class assumes 3
(the default) by guessing controller/method/param
where "param" is the method's first/only argument.
However, your routing has the page number in the second segment, so just set it to 2
.
Upvotes: 2
Reputation: 257
Check the great examples given in the codeigniter userguide, http://ellislab.com/codeigniter/user-guide/libraries/pagination.html
Upvotes: 0