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

SS3 call a function from different DataObject


Reply

5 Posts   466 Views

Avatar
voodoochile

1 February 2013 at 10:16pm Community Member, 52 Posts

Hi All

This may be simple but im just not sure

I have a dataobject extension that has a function with a query in it, i want to access that function from a different dataobject extension.
Can this be done? and how?

Thanks

Avatar
kinglozzer

2 February 2013 at 12:25am Community Member, 146 Posts

Create it as a static function:

Class MyDataObject extends DataObject {

public static function foo() {
// Do some querying
}

}

You can then call it by doing:

MyDataObject::foo()

Avatar
voodoochile

2 February 2013 at 9:33pm Community Member, 52 Posts

Hi Kinglozzer

Thanks for your reply, when i made the function public static the wheels came off a bit and nothing worked.

although this gives me something to go on unfortunatly i have little time to explore this right now so i will plug away as i get time and try a few things and see what i get working

thanks again

voodoochile

Avatar
Willr

4 February 2013 at 8:05pm Forum Moderator, 5511 Posts

If it's static you need to refer to the extension classname (e.g MyDataExtension::foo()). If your method is instance based you need to go $this->owner->foo().

Avatar
voodoochile

5 February 2013 at 10:35pm Community Member, 52 Posts

Thanks Willr

I managed to work that bit out as in MyDataExtension::foo() and kind of got it working but not well, in the page view it returns a value for each object but dosn't seem to be running the query.

at this point i think i need to play around a little with this to get the result i am looking for.