Error on Page Defaults when attempting to call user Avatar

Permalink 1 user found helpful
I modified the Blog_entry page type to include a user's avatar (if it exists) but when I go to Page Defaults to set up the comments block etc... I'm getting thrown this error:

Fatal error: Call to a member function hasAvatar() on a non-object in /home/rynomed1/public_html/corporateblog/packages/cannonf700_corporate_blog/themes/corporate_blog/blog_entry.php on line 20
here is the code i'm using:
<?php  if ($ui->hasAvatar()) {
                          $avatarImgPath = $av->getImagePath( $ui, false );  
                          if( substr($avatarImgPath,0,strlen(DIR_REL))==DIR_REL ) $avatarImgPath=substr($avatarImgPath,strlen(DIR_REL));
                          $thumb = $ih->getThumbnail( DIR_BASE.$avatarImgPath, 32, 32); 
                          if($thumb->src){ 
                                ob_start();
                           $ih->outputThumbnail(DIR_BASE.$avatarImgPath, 32, 32); 
                           $avatarHTML=ob_get_contents();
                                ob_end_clean();
                          }else{ 
                                $avatarHTML = '<img style="align:middle" src="'.$avatarImgPath.'" alt="" />'; 
                          }    
                        echo $avatarHTML;
                       }
               ?>

Any ideas?
Thanks,
Ryan Vars
aka cannonf700

cannonf700
 
cannonf700 replied on at Permalink Reply
cannonf700
BUMP! Anyone?
Ekko replied on at Permalink Reply
Ekko
I'm dealing with the same right now with the blog page type, in which I cant open the defaults page for the blog.

Fatal error: Call to a member function getUserUserBio() on a non-object in /home/content/e/d/i/edisan/html/edisan/packages/theme_name/themes/theme_name/blog_entry.php on line 7

Almost the exact same boat...... I think maybe there's something missing with the theme not recognizing composer, but this is the first time I have dealt with this, and haven't seen it discussed.
cannonf700 replied on at Permalink Reply
cannonf700
Bueller? Bueller? Bueller?
cmerritt replied on at Permalink Reply
cmerritt
Did this ever get resolved as I have the same issue.
cannonf700 replied on at Permalink Reply
cannonf700
This is what we found to work:
<?php if(isset($ui)) { ?>
<?php  if ($ui->hasAvatar()) {
                          $avatarImgPath = $av->getImagePath( $ui, false );  
                          if( substr($avatarImgPath,0,strlen(DIR_REL))==DIR_REL ) $avatarImgPath=substr($avatarImgPath,strlen(DIR_REL));
                          $thumb = $ih->getThumbnail( DIR_BASE.$avatarImgPath, 32, 32); 
                          if($thumb->src){ 
                                ob_start();
                           $ih->outputThumbnail(DIR_BASE.$avatarImgPath, 32, 32); 
                           $avatarHTML=ob_get_contents();
                                ob_end_clean();
                          }else{ 
                                $avatarHTML = '<img class="left" src="'.$avatarImgPath.'" alt="" />'; 
                          }    
                        echo $avatarHTML;
                       }


This is compliments of the guys at C5mix
superuseralan replied on at Permalink Reply
This fix - through catching the lack of an object in $ui - seems to work for me too.

The problem I had was when viewing some user information in a modified block, that only showed as an issue ('Call to a member function xxx() on a non-object') when going into Page Types -> Default.

Adding the test:
if(isset($ui)) {
to catch an unset or "null" value for $ui before attempting the call to the function:
$ui->getAttribute('first_name')
has fixed it for me.

Don't know why the $ui is not set in this view, as my code inclues:
$c = Page::getCurrentPage();
$uID = $c->getCollectionUserID();
$ui = UserInfo::getByID($uID);
immediately before the getAttribute call. No errors when viewing from the front end or editing pages based on the page type.

Still new to all this, but this one seems to have caused quite a few headaches! Hopefully this will help.