New Community Forums are coming. Watch this space for news.

Answered Update Username

Subscribe: RSS
  • Just emphasizing that if you only need data from one, you don't need to get both. It depends on what you have. In the front end, you always have $modx->user (the modUser object). If you need the profile, you can get it with this:

    $profile = $modx->user->getOne('Profile');


    Suppose, though, that you only have the user ID for some other user and want to send an email. There's no need to get the user object unless you also need the username.

    $profile = $modx->getObject('modUserProfile', array('internalKey' => $userId));
    $email = $profile->get('email');
    $fullName = $profile->get('fullname');


    If you do need the username, you can add this step at the end:

    $user = $profile->getOne('User');
    $username = $user->get('username');


    If you only have the ID and you want both the modUser and modUserProfile objects, a faster way is to use $modx->getObjectGraph(), which will only make one query to the database, but that's more complicated.
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
    • Ok totally understand, its just giving us more freedom to access what we need, got it. Thanks! smiley