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

    I have the following code in a loop:

    $c = $modx->newQuery(’modUserProfile’);
    $c->where(array(’internalKey’=>$userInfos->get(’id’)));
    $contactInfos = $modx->user->getOne(’Profile’,$c);

    $userInfos->get(’id’) value changes in the loop but $contactInfos is always returning the infos of the first profile found in the DB even if $userInfos->get(’id’) changes.

    any suggestions?


    thanks
      • 28215
      • 4,149 Posts
      Is $userInfos a modUser object? If so, why not just do:

      $profile = $userInfos->getOne('Profile');
      


      ?
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 818
        • 23 Posts
        No $userInfos is a custom Object.
          • 3749
          • 24,544 Posts
          If I’m understanding what you’re trying to do, $modx->user won’t ever change (it’s you) so you’re always going to get the same user profile.

          Get the user object first with $modx->getObject(’modUser’,$userInfos->get(’id’));

          FYI, you can add extra fields to the regular user Profile extended fields, so you don’t necessarily have to create a custom DB table or any new objects. I haven’t used them, but I believe the Login package now comes with snippets to display and change user info in the Profile.
            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
            • 28215
            • 4,149 Posts
            Or, just do this:

            $contactInfos = $modx->getObject('modUserProfile',array(
               'internalKey' => $userInfos->get('id'),
            ));
            


            Or, better, add ’modUserProfile’ as an alias in your custom userInfos xPDO schema object definition:

            <aggregate alias="Profile" class="modUserProfile" local="id" foreign="internalKey" cardinality="one" owner="local" />
            


            And then do:

            $profile = $userInfo->getOne('Profile');
            
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 818
              • 23 Posts
              so simple! I’m spending so much time to figure simple stuff on Revo!
              Thanks a lot!