Welcome Guest, Not a member yet? Register   Sign In
default_controller problem
#1

[eluser]Santiag0[/eluser]
Hi! I'm starting with CI. I have a little problem when I try to set the router of the default_controller.
Code:
$route['default_controller'] = 'welcome'; //It's OK
$route['default_controller/([a-z0-9])'] = 'users/name/$1'; //Doesn't work :(
I need that because I need to copy the functionality of fotolog:
eg. fotolog.com/jhon
so i need a friendly URI, like myweb.com/user_loco
and the user see his profile.

Thanks a lot!!
#2

[eluser]Doosje[/eluser]
I think you mean
Code:
$route['default_controller'] = 'welcome';
$route['welcome/([a-z0-9])'] = 'users/name/$1';
the uri becomes
http://localhost/welcome/username
and then loads controller users, function name, and passes the $1 to the function. (or you can work with the this->uri->segment or somethign similar.
#3

[eluser]Santiag0[/eluser]
Really thanks, you are great!!
I try your code this night, when i arrive to home. Thanks again Smile
#4

[eluser]Santiag0[/eluser]
Sorry, doesn't for my. Do you think in another solution?

Thanks!
#5

[eluser]Doosje[/eluser]
i dont; think it's my code .. but youre regex !!!
Code:
$route['welcome/([a-z0-9])'] = 'users/name/$1';
just seeks one character after welcome

Code:
$route['welcome/([a-z0-9]+)'] = 'users/name/$1';
should work bettter
#6

[eluser]Santiag0[/eluser]
Sorry, but didn't work too. I try with some variants and always show error 404. I think that is it because always try to load a class, if I put:
http://localhost/
Show welcome
If i put
http://localhost/usernameX
Try to load a class, so display "404 Page Not Found"

I think that the solution its put a code to modify all urls, in this way:
If ($this->uri->segment[0]) != 'go')
{
$this->uri->segment[2] = $this->uri->segment[0]
$this->uri->segment[0] = 'users';
$this->uri->segment[1] = 'name';
}
else
//this->uri->segment[0] is equal to go, so the second is the correct class, the third the method, etc...
array_shift($this->uri->segment); //Shift an element off the beginning of array

When i can put this code?

Thanks a lot for your help, Big Student!!
#7

[eluser]Tom Glover[/eluser]
Have a look here: http://ellislab.com/codeigniter/user-gui...uting.html
#8

[eluser]Santiag0[/eluser]
Thanks, i read that a lot of times but i dont found the solution. If you can help me in some way, i apreciate it.

Thanks again,
Santiago




Theme © iAndrew 2016 - Forum software by © MyBB