Welcome Guest, Not a member yet? Register   Sign In
Dynamic routing...
#1

[eluser]William Rufino[/eluser]
Hello everyone,

I have a question for you "codeigniter pros".

i want to create a route $route['(:any)'] = 'users/get/$1';

www.mysite.com/williamhrs

BUT if I do that, i'll have to create every route possible have manually, and that wouldn't be good cuz there is a lot of them!

is there a way redirect to another route if $1 isn't found?

Sorry for my english, it is a little rusty!
#2

[eluser]toopay[/eluser]
Of course, it would be terrible. if you expecting to have a uri such 'www.mysite.com/williamhrs', apparently you have to define all the names of your controller, even its function, into a verryy long line routes configuration...

maybe, the best way is to adding some little prefix in your route, like

Code:
$route['u_([a-z]+)'] = "users/get/$1";
#3

[eluser]William Rufino[/eluser]
Would it be possible to make a hook to check is the user exists, if it a user it goes to the user controller, if not it keeps going where'ever it was or 404 ?
#4

[eluser]toopay[/eluser]
I think, its possible(if you working around it for a while). There are many ways to get the url, as above. You can write configuration route, or intercept (hacking, lol) core library. But, internally, the concept of CodeIgniter url is described on http://ellislab.com/codeigniter/user-gui.../urls.html
#5

[eluser]DBPolito[/eluser]
You can do it of many ways. Here the easier way:

$route['^((?!controller|folders|you_dont_wanna_redirect)\S*)'] = "user/get/$1";

so, in user controller you check in DB if user exists, if not, show 404 page or redirect it.

That's fix?




Theme © iAndrew 2016 - Forum software by © MyBB