2580 Posts in 695 Topics by 540 members
Data Model Questions
SilverStripe Forums » Data Model Questions » onBeforeWrite and DataObjectDecorator
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 1486 Views |
-
onBeforeWrite and DataObjectDecorator

25 February 2010 at 2:20pm
Hi folks
I have just been trying to get onBeforeWrite to perform some actions based on writing to a DataObjectDecorator, which in this case extends the Member DataObject.
I had hoped this would work right off the bat, but it doesn't seem to.
My onBeforeWrite function seems to be called ok within the DataObjectDecorator, but the objects do not seem to available to it, so no $this->ID, $this->changed etc....
Anyone any ideas?
Cheers
Ronan
-
Re: onBeforeWrite and DataObjectDecorator

25 February 2010 at 2:36pm
Use $this->owner->ID instead, that's how you access the decorated object.
mat.
-
Re: onBeforeWrite and DataObjectDecorator

25 February 2010 at 3:55pm
Hey mat
Yep, but the changed + original objects do not seem to be available....
-
Re: onBeforeWrite and DataObjectDecorator

17 September 2010 at 9:45pm Last edited: 17 September 2010 9:46pm
Inside the DataObjectDecorator I've created a new function which uses:
$this->owner->ID
fine, but how do I get to the data from the extraStatics function? -
Re: onBeforeWrite and DataObjectDecorator

18 September 2010 at 12:41am
Same way. Everything you add with extraStatics will become part of the decorated class:
<?php
class MyDataObjectDecorator extends DataObjectDecorator {
function extraStatics() {
return array(
'db' => array(
'MyField' => 'Varchar(255)'
),
'has_one' => array(
'SomeImage' => 'Image'
);
}
function getLowerCasedMyField(){
return strtolower($this->owner->MyField);
}
function getSomeImageTitle(){
if($this->owner->SomeImage()){
return $this->owner->SomeImage()->Title;
}
}
} -
Re: onBeforeWrite and DataObjectDecorator

18 September 2010 at 7:32am
rbquirke, you wont be able to access changed and original as they are private/protected respectively. However, you can use $this->owner->getChangedFields() and $this->owner->isChanged()
| 1486 Views | ||
|
Page:
1
|
Go to Top |



