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

DataObject::get_one(); doesn't work anymore (since Update to 2.4.2)


Go to End


15 Posts   4576 Views

Avatar
oleze

Community Member, 65 Posts

9 October 2010 at 8:53am

I have a LatestNews function which shows the latest news on my startpage. That worked really well (since it's from the tutorial), but doesn't anymore. I looked in the database for my NewsHolder and it's there as it should. Does anyone have this error too?

function LatestNews($num=3) {
  		$news = DataObject::get_one("NewsHolder");
  		return ($news) ? DataObject::get("NewsPage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
	}

Avatar
swaiba

Forum Moderator, 1899 Posts

9 October 2010 at 9:13am

I'd be surprised if DataObject::get_one did not work any more, maybe you could explain the error a bit more and provide details of how the function did operate, and how it does now to help.

Avatar
oleze

Community Member, 65 Posts

9 October 2010 at 9:16am

Well before the update it worked as it supposed to be in http://doc.silverstripe.org/tutorial:2-extending-a-basic-site (Section: Showing the latest news on the homepage). But now, it doesn't show any news on my homepage.

Avatar
swaiba

Forum Moderator, 1899 Posts

9 October 2010 at 9:43am

ok that function is not behaving as you expect, but I am telling you dataobject::get_one works and my guess is the function will work for you but there is likely something with your data that may have changed... for example recently when upgrading a site the ClassNames were randomly blanked in the site tree... see here... http://silverstripe.org/all-other-modules/show/285615#post285615... I'd guess it was that as your function also relies on dataobject::get page and the page data might be mangled...

have you verified all of your data and debugged (e.g. put Debug::show() all over the place) the data flowing through the function?

Avatar
oleze

Community Member, 65 Posts

9 October 2010 at 10:25am

I tried

Debug::show(DataObject::get_one("NewsHolder"));

within my function but there is no output for that.

Avatar
swaiba

Forum Moderator, 1899 Posts

9 October 2010 at 10:34am

Edited: 09/10/2010 10:37am

What does the data in the database look like? For that to work there needs to be

a) a row in 'NewsHolder'
b) a row in SiteTree & SiteTree_Live with matching id(s) to a with ClassNames present and correct
(assuming these are extensions of Page like in the tutorial)

is this true?

Avatar
oleze

Community Member, 65 Posts

9 October 2010 at 10:42am

Well, the interesting thing is, that there is no table called "NewsHolder". There are tables for "NewsPage" (the children). Because of that, I thought that would be the problem, installed a clean version of 2.4.2 and added the code from the tutorial. In that new database of the test-version, there is also no table "ArticleHolder" ("NewsHolder") but the function works. Damn.

Within Sitetree and Sitetree_Live the IDs are okay.

Avatar
swaiba

Forum Moderator, 1899 Posts

9 October 2010 at 10:51am

please post the newsholder code
but there is a row in sitree&live with newsholder in the classname?

Go to Top