regex help |
[eluser]Thorpe Obazee[/eluser]
How can I use the CI routing to figure out this. Every URL with the controller, user, that does not have the method, 'register' and 'login' should be routed to 'user/view/$1 $route['user/[^register]'] = "user/view/$1"; I currently have this and I know this doesn't work. It produces a 404 when I go to 'user/username' but is ok when I go to 'user/register'.
[eluser]dmiden[/eluser]
Code: $route['user/(?:(?!register|login).)*'] = "user/view/$1"; If you want it to still use the old you can use $this->uri->rsegments(n);
[eluser]Thorpe Obazee[/eluser]
User is my controller. Not the view. Can you explain how you got to that regex?
[eluser]dmiden[/eluser]
I meant view as in the method in your controller ![]() F.ex. if you would like to get the $1 from user/view/$1 you would normally use $this->uri->segment(3) but since you've routed the url it's now, $this->uri->segment(2) example: http://localhost/user/chamyto as chamyto is the 2nd param If you instead want the routed URI segment you could use $this->uri->rsegment(n) then $this->uri->rsegment(3) would be chamyto Use http://www.regular-expressions.info/refadv.html for advanced reference in reg exp ![]()
[eluser]Thorpe Obazee[/eluser]
![]() but $this->uri->rsegment(3) isn't giving me anything... just blank.
[eluser]dmiden[/eluser]
Try checking the data using print_r($this->uri->rsegment_array());
[eluser]Thorpe Obazee[/eluser]
although the $this->uri-segment(2) is working. will check.
[eluser]Thorpe Obazee[/eluser]
Array ( [1] => user [2] => view [3] => ) ok nothing is available...
|
Welcome Guest, Not a member yet? Register Sign In |