Problem with _remap function (trying to redirect) [SOLVED] |
[eluser]tommizzle[/eluser]
Hi all, I have just started using CI about 2 days ago, and have come into a problem with the _remap function. I'm trying to redirect anything off the 'www.root.com/username' to 'www.root.com/profile/username', and have no idea where I'm going wrong - Any help will be appreciated. Controller: Code: <?php Model: Code: <?php Apologies for the crappy code ;p
[eluser]andrewtheandroid[/eluser]
hey there so you can't use the redirect() function? in the url_helper class. edit: like umm redirect('profile/'.$username); ?
[eluser]andrewtheandroid[/eluser]
also have you tested the is_valid_user() by itself? returning the right value? u can test if ur redirect is working by hardcoding $is_user to true and see if it works?
[eluser]tommizzle[/eluser]
Hi andrew, I just tried the redirect - still no good I have tested is_valid_user() on it's own like this: if($is_user == false): echo 'false'; else: echo 'true'; endif; it returned false on the homepage, and 404 when i tried to put a username after the www.root.com/ I think I'm definitely being insanely stupid somewhere here. Thanks for your help, Tom Edit: I just tried hardcoding $is_user to true, and still got a 404 when i put a username on the end.
[eluser]BrianDHall[/eluser]
www.root.com/username wouldn't work unless you were using a special route. _remap is only called if the constructor is called, so you'd need www.root.com/home to activate remap, and www.root.com/home/username to get it to redirect to profile/username. www.root.com/username causes CI to look for the username controller unless you have routed it in some special way, which of course doesn't exist so 404.
[eluser]tommizzle[/eluser]
Thanks BrianDHall. So is there any other way to run the username off the root? Thanks, Tom
[eluser]BrianDHall[/eluser]
[quote author="tommizzle" date="1257458339"]Thanks BrianDHall. So is there any other way to run the username off the root? Thanks, Tom[/quote] Sure, you need a sort of negative route. You define a route with regex that says "if I am not asking specifically for these controllers, then reroute it to this". I just so happen to do exactly this. Here you go: Code: // Route everything but mentioned controllers to default controller, allowing short urls to work. So stick in what you do not want rerouted, and then everything else will be rerouted to whatever you want. So long as there isn't someone with a username the same as one of your controllers (the easiest way to handle this is manually create a user with the username of each of your controllers, to reserve it and guarantee you never have a conflict), it should work as you think it would.
[eluser]andrewtheandroid[/eluser]
hey tom http://ellislab.com/codeigniter/user-gui.../urls.html under enabling query strings you could try to enable it so you can go root.com/index.php?username=this but other than that I think it's prob better to make a different controller because what you are affectively doing is logging in without a password yeh? so you could do root.com/profile/username then in ur "profile" controller have ur code there.. use the segment() function go get ur username and if it doesn't exist redirect them to home. |
Welcome Guest, Not a member yet? Register Sign In |