21298 Posts in 5735 Topics by 2603 members
General Questions
SilverStripe Forums » General Questions » Call a function after getting a specifc page by DataObject::get
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 441 Views |
-
Call a function after getting a specifc page by DataObject::get

11 September 2011 at 12:28pm Last edited: 11 September 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.
-
Re: Call a function after getting a specifc page by DataObject::get

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.
| 441 Views | ||
|
Page:
1
|
Go to Top |


