Welcome Guest, Not a member yet? Register   Sign In
regex help
#1

[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'.
#2

[eluser]dmiden[/eluser]
working on a fix sec
#3

[eluser]dmiden[/eluser]
Code:
$route['user/(?:(?!register|login).)*'] = "user/view/$1";
note that the view controller will get the current URI segments.
If you want it to still use the old you can use $this->uri->rsegments(n);
#4

[eluser]Thorpe Obazee[/eluser]
User is my controller. Not the view.

Can you explain how you got to that regex?
#5

[eluser]dmiden[/eluser]
I meant view as in the method in your controller Smile
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 Wink
#6

[eluser]Thorpe Obazee[/eluser]
Smile I know that much about the uri helper

but $this->uri->rsegment(3) isn't giving me anything... just blank.
#7

[eluser]dmiden[/eluser]
Try checking the data using print_r($this->uri->rsegment_array());
#8

[eluser]Thorpe Obazee[/eluser]
although the $this->uri-segment(2) is working.
will check.
#9

[eluser]Thorpe Obazee[/eluser]
Array ( [1] => user [2] => view [3] => )

ok nothing is available...
#10

[eluser]dmiden[/eluser]
Odd, well just use $this->uri->segment then Smile




Theme © iAndrew 2016 - Forum software by © MyBB