We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!

Answered Update Username

    • 3749
    • 24,544 Posts
    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
      • 46886
      • 1,154 Posts
      Ok totally understand, its just giving us more freedom to access what we need, got it. Thanks! smiley