Welcome Guest, Not a member yet? Register   Sign In
Annoyed with routes! :(
#1

[eluser]Mischievous[/eluser]
Ok... so, i've been struggling with this for the past hour.

I have:

Code:
$route['account'] = "account";
$route['account/:any'] = "account/$1";

When routing the
Code:
$route['account/:any'] = "account/$1";

I keep getting a 404 page. Is this route passing a variable to the function i specify or redirecting the uri?
#2

[eluser]mddd[/eluser]
These routes do nothing. You are directing them to the same values!
'account' -> 'account'
'account/somevalue' -> 'account/somevalue'
In the second one, you need to specify a method (function), like 'account/:any' -> 'account/index/$1'
otherwise the system will look for the function 'somevalue' in your controller!
#3

[eluser]danmontgomery[/eluser]
The routes are regular expression patterns, so the substitution ($1, $2, etc) only work when you specify groups:

Code:
$route['account/:any'] = "account/my_method";

Will route to my_method() in the account controller, whenever the url matches account/{anything here}.

Code:
$route['account/(:any)'] = "account/my_method/$1";

Will pass $1 to my_method() in the account controller.
#4

[eluser]Mischievous[/eluser]
mddd && noctrum! Thanks for speedy reply!

@mddd -> "otherwise the system will look for the function ‘somevalue’ in your controller! "

<-- thats exactly what I was trying to do! Wink

@noctrum ->
Code:
$route['account/(:any)']

that grouping allowed me to pass the values to my controller! Thanks a bunch!




Theme © iAndrew 2016 - Forum software by © MyBB