Welcome Guest, Not a member yet? Register   Sign In
Routes Problem
#1

[eluser]Unknown[/eluser]
Hi!

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

Here is my routes config.

Code:
$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.

Exemple:
exemple.com/search/hello/page/2/

It works but if you manipulate the URL like this for example:
exemple.com/search/hello/page/asd/

You get an error instead of the 404 page.

Someone that can help me with this?

Thanks!
#2

[eluser]PhilTem[/eluser]
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
#3

[eluser]Unknown[/eluser]
Hm, maybe that's the way to go but it works with my other routes.

For example this route work perfect.

Code:
$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.
#4

[eluser]Aken[/eluser]
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




Theme © iAndrew 2016 - Forum software by © MyBB