Welcome Guest, Not a member yet? Register   Sign In
URL with Username or ID Value
#1

[eluser]RMinor[/eluser]
I have a website with user profiles. In the database each profile has an id value, and if the user wants, a username as well (similar to Facebook). How would you guys recommend that I do searching, displaying the profile, etc. if they have a username? I want the default URL display to be the username and then degrade to using the id if no username is available. I thought about doing a hook because to extend the base controller would mean changing each controller (of course there is search and replace). Any suggestions are greatly appreciated.
#2

[eluser]Otemu[/eluser]
Hi,

If you need to display a list of profiles, which link to each user page, then in your foreach loop you probably have to do a check to see if the user has a username and if not then use id as the hyperlink.

foreach($profile as $row){
empty($row[username]) ? $row[id] : $row[username];
}

If a user has the username John and the ID 1234567, when the url yoursite.com/1234567 is used you could run a query on username and ID with a LIMIT 1.

1.Once results are returned you would check once again if username empty, if username is empty then you would just display the page as usual.
2.If however username is not empty you would check if username matches the segment, if it does match then you would display page as normal.
3.If however username is not empty and doesn't match the segment then you could redirect to the new url yoursite.com/John, you either leave it like that or if you don't want to make another database call maybe use flashdata to load all the profile data, if you do use flashdata then you will need to check this initially if flashdata exists before running any queries.
4. If no results then display user doesn't exist.

Your use similar functionality when doing a search, you would search both ID and Username and return the correct page depending if username exists if not then display ID url.

This method requires both username and ID to be unique, if a user can have the same username as someone else ID then your need to have extra functionality to handle that

Not sure if that what your looking for but that my 2 cents Wink






Theme © iAndrew 2016 - Forum software by © MyBB