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.

Archive /

Our old forums are still available as a read-only archive.

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

onAfterWrite?


Go to End
Reply


12 Posts   5135 Views

Avatar
UncleCheese

Forum Moderator, 4094 Posts

9 September 2008 at 5:50am

Is there such a thing? Best I can do is overload the write() function like so..

public function write() {
parent::write();
// do some stuff
}

The problem is, the "do some stuff" gets executed 4 times. Any idea why write() gets called so many times? Once for each relation, maybe? And what can I do about this?

Avatar
Willr

Forum Moderator, 5513 Posts

9 September 2008 at 12:20pm

There should be an onAfterWrite method you can use. Well theres a onAfterWrite() in trunk at least.

Avatar
UncleCheese

Forum Moderator, 4094 Posts

9 September 2008 at 12:44pm

Cool. Any idea why the write() method runs four times on my updates? Does it run once for every related object?

What I'm trying to do is take data that is saved on the object and duplicate some of the record info into another table when the form is saved. The problem is, when the write() method gets executed 4 times, it makes 4 insertions into that table.

Avatar
UncleCheese

Forum Moderator, 4094 Posts

9 September 2008 at 12:46pm

Also, while I have you here... I'm wondering, how do you specify the difference between data that was already saved on the record versus info that the user is saving into it through the form?

$this->FieldName
vs.
$this->record['FieldName']

doesn't seem to bring different results for me. Should $this->record be populated with the user's form data?

Avatar
Willr

Forum Moderator, 5513 Posts

9 September 2008 at 1:23pm

Ive just had alook at onBeforeWrite() and it looks like the current value is stored in $this->Field and the new data in $_POST['Field']. Just tried the same with onAfterWrite and it returned exactly the same - $this->Field contained the old values hmm.

Avatar
Hamish

Community Member, 712 Posts

11 September 2008 at 2:24pm

I'm experiencing similar problems - onBeforeWrite seems to execute multiple times, onAfterWrite does not appear to execute at all.

Avatar
Hamish

Community Member, 712 Posts

11 September 2008 at 2:25pm

ah, found this on another post:

//WHATCH OUT: The function onAfterWrite() is only useable when you use the Daily builds, it's not included in the Version 2.2.2
function onAfterWrite()

Avatar
UncleCheese

Forum Moderator, 4094 Posts

12 September 2008 at 12:15am

Interesting. Thanks for that. Did we ever figure out why write() and onBeforeWrite() fire so many times?

Go to Top