• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routes Problem


I have simple routes problem that I can't figure out how to solve.

Here is my routes config.

$route['search/(:any)'] = 'playlists/search/$1';
$route['search/(:any)/page/(:num)'] = 'playlists/search/$1';

What I need to accomplish is that the pagination only accepts numbers. That's what the last route is for, but it won't work.


It works but if you manipulate the URL like this for example:

You get an error instead of the 404 page.

Someone that can help me with this?


Why don't you just make the check for numeric arguments in your controller? Would be much easier and you can see what lines of code do the manipulation Wink

Hm, maybe that's the way to go but it works with my other routes.

For example this route work perfect.

$route['popular'] = 'playlists/orderby/popular';
$route['popular/page/(:num)'] = 'playlists/orderby/popular';

example.com/popular/page/2/ = Works
example.com/popular/page/asd/ = 404

So it feels better to use the same method for every pagination case and not mix ways if doing it.

You need to reverse their order. CI will go through the routes in order from top to bottom until it finds one that matches. Your first one will match search/ANYTHING, so it will always stop there.

Also, since those two routes go to the same place, the second one is kind of unnecessary, unless you actually want to do something with the :num

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.