Welcome Guest, Not a member yet? Register   Sign In
routes problem ? (thx for reading)
#5

[eluser]Michael Ekoka[/eluser]
I'll try to give a crack to your problem. I'm writing this from the top of my head here so this may or may not work at the first trial. Two problems that i see with your regex:

1-) the regex syntax is wrong or at least it will not behave as expected. I'll try to explain what your regex is doing at the moment:
what you have:
Code:
$route['([cs|sk|pl])/(.*)'] = "$2/$1";
// - check if i have 1 character from this list {cs|kpl} 1 time: [cs|sk|pl]
// - group the resulting character and backreference it with $1: ([cs|sk|pl])
// - followed it by a slash: ([cs|sk|pl])/
// - followed by any character 0 or more times: ([cs|sk|pl])/.*
// - group the "any character 0 or more times" to backreference it with $2: ([cs|sk|pl])/(.*)
what you want:
Code:
$route['(cs|sk|pl)/(.*)'] = "$2/$1";
// - check if i have one of these strings "cs","sk" or "pl" 1 time and backref it to $1: (cs|sk|pl)
// - followed by a slash: (cs|sk|pl)/
// - followed by any character 0 or more times, grouped to be backrefed with $2: (cs|sk|pl)/(.*)

2-) Second problem: your language code is not made optional, if you don't include it in the url, your routing may give some unexpected results.
what you actually want:
Code:
$route['(?:(cs|sk|pl)/)?(.*)'] = "$2/$1";
// - check if i have one of these strings "cs","sk" or "pl" 1 time and followed by a slash: (cs|sk|pl)/
// - whatever is in between the parentheses is considered to be the first backreference $1.
// - Now, group the whole inside non-capturing parenthesis:  (?:(cs|sk|pl)/), that way i don't need to back reference this second outer group.
// - Now, make the entire latest group optional: (?:(cs|sk|pl)/)?
// - that group, if it is set is followed by any character 0 or more times: (?:(cs|sk|pl)/)?.*
// - Now, group the "any character 0 or more times" in capturing parenthesis to make it the second backref: (?:(cs|sk|pl)/)?(.*)

I have posted something similar about internationalization via uri and routing, if you're interested go here.


Messages In This Thread
routes problem ? (thx for reading) - by El Forum - 01-09-2008, 04:18 PM
routes problem ? (thx for reading) - by El Forum - 01-09-2008, 04:25 PM
routes problem ? (thx for reading) - by El Forum - 01-09-2008, 04:47 PM
routes problem ? (thx for reading) - by El Forum - 01-09-2008, 04:55 PM
routes problem ? (thx for reading) - by El Forum - 01-09-2008, 06:00 PM
routes problem ? (thx for reading) - by El Forum - 01-09-2008, 06:26 PM
routes problem ? (thx for reading) - by El Forum - 01-09-2008, 06:44 PM
routes problem ? (thx for reading) - by El Forum - 01-10-2008, 12:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB