We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20014
    • 200 Posts
    here’s the docs on what cyclissmo was talking about.http://rtfm.modx.com/display/ADDON/Login.Using+Pre+and+Post+Hooks

    I can see exactly what cyclissmo is saying, but as a fellow designer, I would definitely have to dig to find how to automatically create a resource for than user...knowing the modx community, the answer is here somewhere...
      • 3749
      • 24,544 Posts
      This assumes that the user is logged in and registered. Not sure if that’s the case. If not logged in, you’d have to get the user with $modx->getObject() based on the username unless all the user info you want is available in the hook.

      <?php
      $userName = $modx->user->get('username');
      $profile = $modx->user->getOne('Profile');
      $fullName = $profile->get('fullname');
      $parentId = 'desired_parent_id';
      $content = '<p>Desired Page Content</p>';
      $templateId = 'id_of_desired_template';
      
      $resource = $modx->newObject('modResource');
      
      $resource -> set('pagetitle',$userName);
      $resource ->set('alias', $userName);
      $resource ->set('longtitle', 'Personal page of ' . $fullName);
      $resource -> set('parent',$parentId);
      $resource -> set('content', $content);
      $resource -> set('template', $templateId);
      $resource -> set('published', '1');
      $resource -> set('richtext', '1');  // or 0
      
      $resource -> save();
      ?>


      smiley
        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
        • 20014
        • 200 Posts
        my god bobray!! you are awesome!! how long before your book hits shelves...you make it seem so simple!!

        I am not hijacking the thread here but it will definately help the op (and me as well heh heh) but could he/she call a html chunk (chunk is a container holding all your html code that modx can reference and insert where you want) like this?

        $content = '[[$chunk]] ';
          • 3749
          • 24,544 Posts
          Thanks for the very kind words, but as I often say, don’t thank me until it works. wink

          Per your question: Yes and no. Yes on using the chunk, no on using a tag to get it -- no tags in snippet code. It would be this:

          $content = $modx->getChunk($chunk);


          or

          $content - $modx->getChunk('ChunkName');


          Any tags in the chunk would be processed by getChunk().
            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
            • 20014
            • 200 Posts
            if the snippet is being used with the register form of Login.Rester and the user hasn’t logged in yet then when you say:
            If not logged in, you’d have to get the user with $modx->getObject() based on the username unless all the user info you want is available in the hook
            the we could retrieve the username like this?:
            $userName = $modx->getObject('username') 
              • 3749
              • 24,544 Posts
              Quote from: modxlearner123 at Aug 27, 2010, 11:27 PM

              if the snippet is being used with the register form of Login.Rester and the user hasn’t logged in yet then when you say:
              If not logged in, you’d have to get the user with $modx->getObject() based on the username unless all the user info you want is available in the hook
              the we could retrieve the username like this?:
              $userName = $modx->getObject('username') 


              I don’t know what I was thinking there. If the user isn’t logged in, there’s no use trying to get the username from the DB because MODx has no idea who the user is.

              If the register form has been filled out and submitted, the username should be available as $_REQUEST[’username’], but I’m not sure you’d want to do anything with it because the user hasn’t been activated by clicking on the link in the activation email and might never do so (especially if it’s a spam bot of some kind).

              On the Confirm Registration page, a snippet could do something like this:

              <?php
              $username = base64_decode(urldecode($_REQUEST['lu']));
              
              /* validate we have correct user */
              $user = $modx->getObject('modUser',array('username' => $username));
              
              if ($user) {
                  /* yes we have */
              
                  /* your code here */
              }
              ?>
              


              FYI, $modx->getObject() always requires the type of object you want it to get as the first argument. The second argument contains the criteria for finding the object (although it can be just an ID):

              <?php
              $user = $modx->getObject('modUser', array('username'=>'JoeUser'));
              //or, if you know the user's ID:
              // $user = $modx->getObject('modUser',12);
              
              if ($user) {
                 $username = $user->get('username');
              } else {
                /* no such user */
              }
                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
                • 20014
                • 200 Posts
                this clarifies quite a bit