Methods for a User on a Public Profile Page

Permalink 1 user found helpful
I would like to get a user's email address and display it on their public profile page (i.e. an "Email John Smith" link from his profile page).

I was using the various User methods ($u->getUserName() and such), however I'm not sure how to load the information for a user relative to the public profile page. $u = new User() will not work obviously, because that's for a currently logged-in user.

Any help?

Proteus
 
andrew replied on at Permalink Reply
andrew
Proteus replied on at Permalink Reply
Proteus
Thanks, but the first link redirects me to a login page. I can't find a how-to that's named "Hello User Block Example" in the docs. Maybe that link needs to be updated?

As for the Users section in the documentation, I've been scanning it and so far it hasn't clicked for me yet. I get the overall concept of what needs to happen (I think), I just don't know how to make it work in code.
pvernaglia replied on at Permalink Best Answer Reply
pvernaglia
I just did something similar, this was a helpful thread:http://www.concrete5.org/community/forums/customizing_c5/get_atribu...
Proteus replied on at Permalink Reply
Proteus
That thread is very helpful, sort of half of what I was looking for. But it made me think in the right way to figure it out! Not in the way I originally thought I would do it, but it worked nonetheless. Instead of trying to get their User ID, I used their Username to get all their user information.

Here's how, for those interested:
In modifying the single page template for public profiles (profile.php) I wanted to display some information about a user on their profile page (for instance, their email).

Because the profile page is already grabbing user-based information, such as their Username, and you can get user attributes and information based on their Username (with UserInfo::getByUserName() ), you can use the code already within the profile page to your advantage.

Assuming you haven't modified the default single page template for profile pages (single_pages/profile.php), here's the code you would use:

Loader::model('userinfo');
$userName = $profile->getUserName(); // use the profile page's loader to grab the user name, and store it in a variable
$ui = UserInfo::getByUserName($userName); // plug the username variable into the User Info model
print $ui->getUserEmail(); // print out something related to that user, such as their email


You can use the other UserInfo methods as well to pull out other information about the user and put it on their profile page.