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.

Data Model Questions /

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

Extending DataObject but still need to call static DataObject methods?

Go to End

3 Posts   1460 Views


Community Member, 9 Posts

17 May 2011 at 3:12am

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.


Community Member, 473 Posts

17 May 2011 at 8:22am

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


Community Member, 9 Posts

17 May 2011 at 9:13pm

Great, thanks a lot!