routes problem ? (thx for reading) |
[eluser]starenka[/eluser]
Hi, trying to implements easy multilang site with uris as: /cs/user/join (or just /user/join) /sk/user/join etc etc.. so i added a route: Code: $route['(cs|sk|pl)/(.*)'] = "$2/$1"; but when i try to get the language segment in controller... Code: class User extends Controller i allways get "the method" segment... any clues? or more elegant solutions?
[eluser]eggshape[/eluser]
how strange...have you tried this Code: $route['([cs|sk|pl])/(.*)'] = "$2/$1"; oh i should also mention that you can write your uri like $method/$language, and then in your method use segment(): Code: public function join()
[eluser]starenka[/eluser]
hi. thx for reply... ad regexp: the regexp seems to be okay (why should i use []?) - your regexp leads to "page not found" ad uri: i know, but i like /$lang/$class/$method/$params better...
[eluser]eggshape[/eluser]
sorry I really don't know why your regexp failed; seems like *proper* regexp lingo, so maybe it's how CI handles this. the brackets aren't really necessary; in regexp-speak, they just mean "only these cases are valid"...like match [1a,] (match 1 or a or ,). since it fails, it must be the way CI handles these regexp for this class. edit: maybe you have an extra forward slash for $2; i would also change the * to + (1 or more) Code: $route['(cs|sk|pl)/(.+)/$'] = "$2/$1"; if your regexp fails to match the URI, then CI uses the URI as the default.
[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"; Code: $route['(cs|sk|pl)/(.*)'] = "$2/$1"; 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"; I have posted something similar about internationalization via uri and routing, if you're interested go here.
[eluser]starenka[/eluser]
hi! heh what to say. look @ my initial post. it's the same regexp you write ![]() maybe i found what's wrong about this. debugged the the Router class a bit and it re-routes my regexp just fine (from $lang/$class/$method to $class/$method/$lang) but then _reindex_segments() screw this big time... dunno if this a normal behaviour, but i realized i don't even need the route. i will just use $this->uri->segment(1) ![]()
[eluser]Michael Ekoka[/eluser]
:lol: my bad, I looked at the wrong regex. It would've saved me 10 minutes. Well in theory your route should work, but i suspect that the source of your problem has to do with this. And yeah, you don't need to include the language code in the route. $this->segment(1) should do just fine.
[eluser]Armchair Samurai[/eluser]
Since you're re-routing things, try using the the ruri functions Code: class User extends Controller |
Welcome Guest, Not a member yet? Register Sign In |