Error in setAttribute()

Permalink 1 user found helpful
Hi Everyone,

I have to set attribute for particular pages using code, so i have tried the below given code, but it shows Fatal error.

$pages = Page::getByID($pages_id->cID);

Fatal error: Call to a member function setAttribute() on a non-object in E:\xampp\htdocs\concrete\job\concrete\models\collection.php on line 220

Any help would be appreciable.
Thank you

View Replies: View Best Answer
jaredquinn replied on at Permalink Reply
My guess would be that your Page::getByID(..) isn't returning a page object (ie. false).

Is $pages_id->cID a valid page ID?

TheRealSean replied on at Permalink Reply
I think Jared is right here it would appear to be a problem with the $pages_id->CID;

You can run this check

if (is_object($pages)) {
echo "Frankie says Relax, don't do it";
echo "Not an Object";

That would also stop the error from appearing as if $pages is not an object then the setAttribute function is not called.
Mnkras replied on at Permalink Reply
or use the simpler way,

$pages = Page::getByPath('derp');
if(!$pages->isError()) //page is not error
SVijay replied on at Permalink Reply 1 Attachment
Hi everyone,

First of all thanks for your responses and sorry for my delayed reply.
I have tried your methods to check the $pages, but there is no error in $pages. Its returning page object.

For more details, please refer the attachment.

Any help would be appreciable.
Thank you
TheRealSean replied on at Permalink Best Answer Reply
Sorry I have not looked at the attachment yet, but I stumbled across a very similar looking error, when attempting to add a thumbnail to the page,

It turned out the value I was adding was null,

attibute was then trying to add,

that caused an error on a non object. could it possibly be the $unique_id[$i] that you are calling?? is actually not reurning anything?

Ill take a look through the attachment later when not at work see if I can be any more fruitful, this was just a quick thought I had while coding last night
SVijay replied on at Permalink Reply

Thanks for your reply. Found and solved the problem.