Jump to:

3430 Posts in 1057 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Extending DataObject but still need to call static DataObject methods?

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

Page: 1
Go to End
Author Topic: 1099 Views
  • tallrobphilp
    Avatar
    Community Member
    9 Posts

    Extending DataObject but still need to call static DataObject methods? Link to this post

    I'm trying to build my site around subclassing DataObject and using ModelAdmin for administrating in the CMS. I want to follow the practise of thick models and thin controllers, so essentially put all the data fetching in the models and then have thin controllers that just call model methods.

    What I'm having trouble with is that when I extend DataModel like so: -

    class Product extends DataModel {...}

    I then still need to call DataModel::get(...) within in order to fetch data. What seems to be a normal OO approach would be to be able to make a call something like this: -

    $this->get() or self::get()

    In order to fetch all my products. It seems that I need to call DataModel::get('Product') even though I've subclassed DataModel. It may be that I've just missed something, but I can't grasp what the approach is supposed to be here. Subclassing DataModel and then still having to tell my data fetch calls which model to fetch from seems odd.

  • simon_w
    Avatar
    Forum Moderator
    471 Posts

    Re: Extending DataObject but still need to call static DataObject methods? Link to this post

    You can use $this->instance_get(), which accepts the same arguments as DataObject::get(), just not the class name.

  • tallrobphilp
    Avatar
    Community Member
    9 Posts
    1099 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.