We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    Hi - Is it possible (I am sure it is.. I just cant work out how!), within a snippet to get the logged in MODx users extended and standard fields and set some of them as defined session vars?

    e.g.

    get the modx user field 'username'
    get the modx extended user field 'monkeys'
    get the modx extended user field 'chickens'


    then set them as session vars - so:

    modx user field 'username' becomes a session variable called 'session_username'
    modx extended user field 'monkeys' becomes a session variable called 'session_monkeys'
    modx extended user field 'chickens' becomes a session variable called 'session_chickens'


    Can anyone help?

    Thanks


    dubbs.

    This question has been answered by BobRay. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      It sounds pretty easy, but maybe I'm misunderstanding you.


      $session['session_username'] = $modx->user->get('username');
      
      $profile = $modx->user->getOne('Profile');
      
      $extended = $profile->get('extended');
      
      $session['session_monkeys'] = $extended['monkeys'];
      
      $session['session_chickens'] = $extended['chikens'];


      If line 3 doesn't work (there are specific situations where it won't), replace it with this:

      $profile = $modx->getObject('modUserProfile', array('internalKey' => $modx->user->get('id')));
        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
        • 8168
        • 1,118 Posts
        Quote from: BobRay at Aug 29, 2016, 03:52 PM
        It sounds pretty easy, but maybe I'm misunderstanding you.


        $session['session_username'] = $modx->user->get('username');
        
        $profile = $modx->user->getOne('Profile');
        
        $extended = $profile->get('extended');
        
        $session['session_monkeys'] = $extended['monkeys'];
        
        $session['session_chickens'] = $extended['chikens'];


        If line 3 doesn't work (there are specific situations where it won't), replace it with this:

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


        Thanks Bob - yep, the first approach works wink