Displaying user's name in profile
I've been trying to display the user's name in their profile with no luck... global $user; ($user->name); displays the currently logged in user... Everything I've read says either to use that or profile_load_profile($user); print $user->name; but neither are working and I can't figure out how to use the $account variable either. This is with Drupal 5. Any suggestions? Jake Roufa 208.557.9390 http://jacobroufa.com
Try the realname module. Idan From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Jacob Roufa Sent: Sunday, August 15, 2010 9:34 AM To: support Subject: [support] Displaying user's name in profile I've been trying to display the user's name in their profile with no luck... global $user; ($user->name); displays the currently logged in user... Everything I've read says either to use that or profile_load_profile($user); print $user->name; but neither are working and I can't figure out how to use the $account variable either. This is with Drupal 5. Any suggestions? Jake Roufa 208.557.9390 http://jacobroufa.com
Nevermind, figured out to use $account->name. This isn't documented at api.drupal.org... Any idea why? Jake Roufa 208.557.9390 http://jacobroufa.com On Sun, Aug 15, 2010 at 12:34 AM, Jacob Roufa <jacob.roufa@gmail.com> wrote:
I've been trying to display the user's name in their profile with no luck... global $user; ($user->name); displays the currently logged in user... Everything I've read says either to use that or profile_load_profile($user); print $user->name; but neither are working and I can't figure out how to use the $account variable either. This is with Drupal 5. Any suggestions?
Jake Roufa 208.557.9390 http://jacobroufa.com
On Aug 14, 2010, at 11:58 PM, Jacob Roufa wrote:
Nevermind, figured out to use $account->name. This isn't documented at api.drupal.org... Any idea why?
On Sun, Aug 15, 2010 at 12:34 AM, Jacob Roufa <jacob.roufa@gmail.com> wrote: I've been trying to display the user's name in their profile with no luck... global $user; ($user->name); displays the currently logged in user... Everything I've read says either to use that or profile_load_profile($user); print $user->name; but neither are working and I can't figure out how to use the $account variable either. This is with Drupal 5. Any suggestions?
$user is always the current user object. profile_load_profile() is sort of an awkward way to get the user's name since it operates by reference: $account->uid = 1337; profile_load_profile($account); I often set up a utility function in template.php that looks something like this: function get_username_from_uid($uid) { $q = "SELECT name FROM {users} WHERE uid = %d"; return db_result(db_query($q, $uid)); } It's useful in corner cases. In your case (on a profile page), $account should already be populated with what you need. print_r() it and make sure you're not missing it? -D
participants (3)
-
Domenic Santangelo -
Idan Arbel -
Jacob Roufa