Jump to:

23369 Posts in 18145 Topics by 2863 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 593 Views
  • bostonmark
    Avatar
    Community Member
    10 Posts

    Call a function after getting a specifc page by DataObject::get Link to this post

    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.

  • Ryan M.
    Avatar
    Community Member
    309 Posts

    Re: Call a function after getting a specifc page by DataObject::get Link to this post

    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.

    593 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.