21492 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1291 Views |
-
check first write action and onAfterWrite method

27 February 2010 at 2:55am
Hello,
I would like to know if it's possible to check if a writing action is the first in onAfterWrite method ? I know it's possible in onBeforeWrite method with a test on the existance of the ID :
function onBeforeWrite() {
parent::onBeforeWrite();if (!$this->ID) {
// first write
}
else {
// next write when updates
}
}But, in onAfterWrite ?
Thanks.
-
Re: check first write action and onAfterWrite method

3 March 2010 at 3:28pm
salut
so you trying to find if the DataObject you just wrote is the first in the DB?
function onAfterWrite(){
parent::onAfterWrite();
$list = DataObject::get($this->ClassName);
return $list->Count();
}
this will return number of DataObjectanyway, you don't need to check if you writing a new DataObject or just updating, th framework does it for you.
-
Re: check first write action and onAfterWrite method

4 March 2010 at 11:18pm
Hi - the first thing that comes into my mind, without delving into any code, is - if you've check it in onBeforeWrite, you can easily save the result in a property, and check the value of that property in onAfterWrite..
| 1291 Views | ||
|
Page:
1
|
Go to Top |


