Fatal error: Call to a member function getAttribute() on a non-object

Permalink
When I go to Pages & Themes/Page Types/Defaults and select this template, I am getting the following error
Fatal error: Call to a member function getAttribute() on a non-object in F:\wamp\www\packages\my_theme\themes\my_theme\member.php on line 40

And here is the offending code
<?php $c = Page::getCurrentPage();
                   $uID = $c->getCollectionUserID();
                   $ui = UserInfo::getByID($uID);
                   echo $ui->getAttribute('full_name'); ?>


The "Full Name" displays perfectly on the page and I only get this error when trying to set up page defaults?

ConcreteOwl
 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
In the page defaults, the page doesn't have an owner yet, so the owner ID returned is null and the rest goes downhill from there.

The easiest fix is probably
if (is_object($ui)){
echo $ui->getAttribute('full_name');
}


That will prevent the dashboard / defaults problem, but allow it to function OK on a real page.
ConcreteOwl replied on at Permalink Reply
ConcreteOwl
Yes John, You are correct that is exactly what was happening,
Once again, Many Thanks for your help..
Dave
JohntheFish replied on at Permalink Reply
JohntheFish
Setting up such pages can often be made a lot easier by using Magic Data ;-)
enlil replied on at Permalink Reply
enlil
Yes! I've noticed some issues with the core blog_post page type not showing the post owners name when not logged in as well. No matter though. I've completely set up my own "blog" page type using pure magic data!!
stewblack23 replied on at Permalink Reply
stewblack23
As usual John you solved my issue. Thanks.