Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

[Notice] Trying to get property of non-object Link to this post


Go to End


4 Posts   2965 Views

Avatar
airscool

Community Member, 4 Posts

4 September 2014 at 2:07am

[Notice] Trying to get property of non-object Link to this post

I have just been approached to tackle an error on a Silverstripe website. The highlighted error is Line 67. Is it perhaps a PHP version error?

---------------------------------

[Notice] Trying to get property of non-object
GET /

Line 67 in /home/brillian/public_html/mysite/code/Page.php
Source

58 // instead of putting Requirements calls here. However these are
59 // included so that our older themes still work
60 Requirements::themedCSS('layout');
61 Requirements::themedCSS('typography');
62 Requirements::themedCSS('form');
63 }
64
65 function LatestNews($number=1) {
66 $holder = DataObject::get_one('BlogHolder', "Title = 'Blog'");
67 return DataObject::get('BlogEntry', "ParentID = {$holder->ID}","Date DESC", false, $number);
68 }
69
70 function LastUpdated() {
71 return DataObject::get('Page', 'ShowInMenus = 1', 'LastEdited DESC', '', 1);
72 }
73

Trace

Page_Controller->LatestNews()
Line 369 of ViewableData.php
ViewableData->obj(LatestNews,,1,,)
Line 823 of ViewableData.php
ViewableData_Customised->obj(LatestNews)
Line 330 of .cache.themes.ruthmorris.templates.Page.ss
include(/home/brillian/public_html/silverstripe-cache/.cache.themes.ruthmorris.templates.Page.ss)
Line 429 of SSViewer.php
SSViewer->process(HomePage_Controller)
Line 202 of Controller.php
Controller->handleAction(SS_HTTPRequest)
Line 143 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)
Line 147 of Controller.php
Controller->handleRequest(SS_HTTPRequest)
Line 199 of ContentController.php
ContentController->handleRequest(SS_HTTPRequest)
Line 67 of ModelAsController.php
ModelAsController->handleRequest(SS_HTTPRequest)
Line 111 of RootURLController.php
RootURLController->handleRequest(SS_HTTPRequest)
Line 282 of Director.php
Director::handleRequest(SS_HTTPRequest,Session)
Line 125 of Director.php
Director::direct(/)
Line 127 of main.php

Attached Files
Avatar
kinglozzer

Community Member, 187 Posts

4 September 2014 at 11:01pm

Edited: 04/09/2014 11:02pm

Hi,

The error is triggered because $holder isn’t an object, so $holder->ID won’t work. The most likely reason you’re getting this is that there isn’t a page being returned by the DataObject::get_one() call.

Make sure there’s a page in the CMS that’s a BlogHolder and has the title “Blog”.

Loz

Avatar
airscool

Community Member, 4 Posts

5 September 2014 at 12:21am

I can't access the CMS.

There is definately a 'blog' folder with appropriate files located in it's 'code' folder.

Avatar
kinglozzer

Community Member, 187 Posts

5 September 2014 at 3:49am

The problem is that it’s looking for a blog page which has presumably been deleted. I’d try amending line 67 to the following:

return ($holder) ? DataObject::get('BlogEntry', "ParentID = {$holder->ID}","Date DESC", false, $number) : false;

Hopefully this’ll make the error disappear. You’ll then need to recreate the “Blog” page in the CMS to get the latest news to display again.

Loz