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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Call a function after getting a specifc page by DataObject::get


Go to End


2 Posts   940 Views

Avatar
bostonmark

Community Member, 10 Posts

11 September 2011 at 12:28pm

Edited: 11/09/2011 12:28pm

I'm trying to write a wrapper function in a page class to get the most recent Calendar page, then call the Events() function on that since Calendar.php has an Events function. I tried the following:

$cal = DataObject::get("Calendar", "", "Created DESC", "", 1);
return $cal->Events();

I get the error:

[User Error] Uncaught Exception: Object->__call(): the method 'events' does not exist on 'DataObjectSet'

I assume it's because DataObject::get returns a DataObjectSet that contains the Calendar object in it. If that's the case, how do I get the Calendar object from that where I can call its Events() method? If I'm wrong, how would I go about accomplishing what I'm trying to do?

Thanks for any help.

Avatar
Ryan M.

Community Member, 309 Posts

11 September 2011 at 6:12pm

If you only need to retrieve one object, then why not use DataObject::get_one? That should return a single DataObject instead of a DataObjectSet and I think your event method should be available then.