Display a user attribute instead of $userName for login / logout code

Hey everyone

I'm no expert on php by any means, so sorry for what is probably an easy question...

I'm using the code as included with concrete5 themes which displays a username when logged in, then once logged out, a sign in link, it is this code:

         $u = new User();
         if ($u->isRegistered()) { ?>
            if (Config::get("ENABLE_USER_PROFILES")) {
               $userName = '<a href="' . $this->url('/profile') . '">' . $u->getUserName() . '</a>';
            } else {
               $userName = $u->getUserName();
            <span class="sign-in"><?php echo t('Currently logged in as <b>%s</b>.', $userName)?> <a href="<?php echo $this->url('/login', 'logout')?>"><?php echo t('Sign Out')?></a></span>
         <?php  } else { ?>
            <span class="sign-in"><a href="<?php echo $this->url('/login')?>"><?php echo t('Member Login')?></a></span>
         <?php  } ?>

Basically, I just want to replace the $userName with an attribute that I've created called First Name, with a handle of firstName...

Can someone please point me in the right direction on how to do this? Cheers.

View Replies:
mesuva replied on at Permalink Reply
You should be able to fetch the user attribute fairly easily:

$ui = UserInfo::getByID($u->getUserID());
$userName = $ui->getAttribute('firstName');

The trick with this is that sometimes you need a UserInfo object, which is like an extension of the User class, so you can do more things with it (like in this case fetch user attributes).