Welcome Guest, Not a member yet? Register   Sign In
HELP - Using Routes.php to turn all paths into parameters.
#1

[eluser]orokusaki[/eluser]
Hi, so what I'm trying to do is bypass all controller / function segments in the URL so that I can have:

http://site.com/param1/param2/param3 ... and so on

I have:

Code:
$route[':any'] = "controller_1/function_1";

and it works fine... except:

If have another controller controller_2, and I go to

http://site.com/controller_2/

it accesses controller_1 and sets the param1 as "controller_2" instead of accessing controller_2

How do I use all segments of the URI as params for a single function, with a condition that if the first segment is a controller it uses that controller instead of passing it as a param?

P.S. I am setting the custom route after the reserved routes.
#2

[eluser]Jelmer[/eluser]
You should declare a route for every url other than those for the wildcard before the wildcard rule (:any).

like this:
Code:
$route['controller_2'] = "controller_2";
$route['controller_2/(:any)'] = "controller_2/$1";
$route['controller_3'] = "controller_3";
$route['controller_3/(:any)'] = "controller_3/$1";
$route[':any'] = "controller_1/function_1";
#3

[eluser]orokusaki[/eluser]
Awesome thanks. I didn't think anything like that would work. Will try it tonight.




Theme © iAndrew 2016 - Forum software by © MyBB