Reputation: 15
This is my situation: I have page localhost/ctc/product to show products and localhost/ctc/product/abcxyz to show detail of individual product abcxyz. It works fine until I want to paginate my main page because list of products is too long. I use usual pagination class to paginate but when I come to next page the url become like this: localhost/ctc/product/1 and I think it mistake the pagination number to a product and the page show nothing. So how can I solve this problem ? Thanks all of you and sorry for my broken English.
Problem solved. Thanks to John B and otporan.
Upvotes: 0
Views: 361
Reputation: 1355
You should limit with regex what can go in the last parameter of url.
You have 3 routes:
ctc/product
ctc/product/abcxyz
ctc/product/1
You must explain to router mechanism that 2 route should accept only string as last param, and that third route can accept only number as last param.
You can do it like this:
$route['ctc/product/([a-z]+)'] = "controller/method/$1";
$route['ctc/product/([0-9]+)'] = "controller/method/$1";
So now you have 2 routes that have the same number of "params" in URI, but router is aware of differences. One will have string as last param, and the last route would have integer as last param.
I didn't have time to test this on local server. But you should get the idea how this should work.
Joust read through docs here: Codeigniter Routing
Upvotes: 1