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.

General Questions

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

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

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


Go to End
Reply

15 Posts   2738 Views

Avatar
oleze

9 October 2010 at 8:53am Community Member, 65 Posts

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

9 October 2010 at 9:13am Forum Moderator, 1796 Posts

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

9 October 2010 at 9:16am Community Member, 65 Posts

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

9 October 2010 at 9:43am Forum Moderator, 1796 Posts

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

9 October 2010 at 10:25am Community Member, 65 Posts

I tried

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

within my function but there is no output for that.

Avatar
swaiba

9 October 2010 at 10:34am (Last edited: 9 October 2010 10:37am), Forum Moderator, 1796 Posts

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

9 October 2010 at 10:42am Community Member, 65 Posts

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

9 October 2010 at 10:51am Forum Moderator, 1796 Posts

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

Go to Top