Welcome Guest, Not a member yet? Register   Sign In
/userclass/usermethod/userid -> /username
#1

[eluser]jstrebel[/eluser]
Wondering how to accomplish this. I have read over the remap and routes stuff but I cant seem to wrap my head around it.


I have a controller runnning smooth in that when http://domain.com/userclass/usermethod/userid is called it does as intended and renders the user data based on userid.

I would like this same action to happen at http://domain.com/username

In the userclass am already querying the db based on userid to retrieve the username, so i gather then that I pass username to some sort of routing/remap function using reg_exp??


Please advise.
#2

[eluser]Michael Wales[/eluser]
Setup routes for every controller/method within your application - then setup a route, at the bottom of the list, like so:
Code:
$route[':any'] = 'userclass/usermethod/';

Within that method look at $this->uri->segment(1), which should be a slug of their username and correspond to a similar field within the database that you will use to retrieve their information.

Also, be sure to not allow people to register usernames that are the same as any of yoru controllers - because then they'll never be able to see their profile page (it will just go to your controller).
#3

[eluser]jstrebel[/eluser]
Thanks for the reply.. and from what i know your solution would work. The only beef I have with it is that you have to put all the route declarations in to cover all the controllers you do not want to tamper with. We already have 20+ controllers and will be adding more. This seems to be a rather un-elegant solution.

Maybe this could be accomplished better with .htaccess rewrites?

Here is what my url's look like.

/profile/u/# --- 'u' is a function to handle 'users'
/profile/v/# --- 'v' is a function to handle 'vendors'

both u, and v use the numeric 3rd uri segment to query the db and pull profile information based on the user_id = #.

One of the fields returned from that query would be $username.. so i can then pass $username to some sort of rewrite function to dynamically recreate the url to /$username

I am sure this can be done with .htaccess... but I dont know how to pass a dynamically generated variable into a .htaccess rewrite rule.

If that is all a bust.. I guess I will then just do as you say and declare routes for all controllers.. Sad
#4

[eluser]hotmeteor[/eluser]
If your controllers are all short (ie. v or u) couldn't you just make it so that a user's name has to be at least 3 or 4 characters?




Theme © iAndrew 2016 - Forum software by © MyBB