We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7045
    • 225 Posts
    Latest Revo/Latest Personalize

    Fatal error: Call to a member function get() on a non-object in /home/deniro03/public_html/clients/test4/core/cache/includes/elements/modsnippet/92.include.cache.php on line 88

    I just noticed this error, as it only happens when I am not logged into the manager (I'm almost always logged in). I followed the file to the following code:
    /* Prepare params and variables */
    $output = '';
    $yesChunk = (isset($yesChunk))? $yesChunk : '';
    $noChunk = (isset($noChunk))? $noChunk : '';
    
    /* Do the work */
     if ($modx->user->hasSessionContext($modx->context->get('key')) ) {
       $output =  $modx->getChunk($yesChunk);
       if (isset($ph)) {
          if ($fullName) {
              $profile = $modx->user->getOne('Profile');
              $modx->setPlaceholder($ph, $profile->get('fullname'));
          } else {
              $modx->setPlaceholder($ph, $modx->user->get('username'));
          }
       }
    } else {
       $output = $modx->getChunk($noChunk);
    }
    
    return $output;
    }
    


    Here is line 88 from the above:
    $modx->setPlaceholder($ph, $profile->get('fullname'));
    


    So I tested the the Personalize call with &fullName=`0` and it seems to work. However, that won't work for my client's site. We need to be able to use the fullname. Anytime I have it set to `1`, we get that error on any page containing a personalize call.

    I hope that all made sense.
      • 3749
      • 24,544 Posts
      It does make sense, and there should be a sanity check in the code to prevent that. It looks like you have a user who is logged in to the current context but doesn't have a User Profile. If you make sure every user has a fullname, it should go away.

      Here's a utility snippet (untested) to find users with no fullname or profile:

      $output = "Checking Users<br />";
      
      $users = $modx->getCollection('modUser');
      
      foreach ($users as $user) {
          $profile = $user->getOne('Profile');
          if (! $profile) {
             $output .= '<br />User has no profile: '  .  $user->get('username') . ' (' . $user->get('id')  . ')';
          } else {
              $profile= $profile->get('fullname');
              if (empty($profile)) {
                  $output .= '<br />User has no fullname: '  .  $user->get('username') . ' (' . $user->get('id')  . ') ';
              }
          }
      }
      
      return $output;
      



      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 7 months ago.]
        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
        • 3749
        • 24,544 Posts
        BTW, here is some updated code for the snippet (untested):

        /* @var $modx modX */
        /* @var $profile modUserProfile */
        
        /* Prepare params and variables */
        $output = '';
        $sp =& $scriptProperties;
        
        $yesChunk = $modx->getOption('yesChunk',$sp, null);
        $noChunk = $modx->getOption('noChunk',$scriptProperties, null);
        $fullName = $modx->getOption('fullName', $sp, null);
        $ph = $modx->getOption('ph',$sp, null);
        
        if( !empty ($fullName) ) {
            $profile = $modx->user->getOne('Profile');
        }
        
        /* Do the work */
         if ($modx->user->hasSessionContext($modx->context->get('key')) ) {
           $output =  $modx->getChunk($yesChunk);
           if ( !empty($ph)) {
              if ($fullName && $profile) {
                  $modx->setPlaceholder($ph, $profile->get('fullname'));
              } else {
                  $modx->setPlaceholder($ph, $modx->user->get('username'));
              }
           }
        } else {
           $output = $modx->getChunk($noChunk);
        }
        return empty($output)? '' : $output;



        ---------------------------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
        MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 7 months ago.]
          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
          • 3749
          • 24,544 Posts
          I just released Personalize 3.3.0-pl with the changes: http://bit.ly/zEo8x7


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            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
            • 7045
            • 225 Posts
            Nice. Thanks Bob. I will give it a shot and report back.
              • 7045
              • 225 Posts
              It works perfectly now, Bob. Thanks again.