Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » onAfterWrite?

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

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

Page: 1 2
Go to End
Author Topic: 4865 Views
  • UncleCheese
    Avatar
    4085 Posts

    onAfterWrite? Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: onAfterWrite? Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: onAfterWrite? Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: onAfterWrite? Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: onAfterWrite? Link to this post

    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.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: onAfterWrite? Link to this post

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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: onAfterWrite? Link to this post

    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()

  • UncleCheese
    Avatar
    4085 Posts

    Re: onAfterWrite? Link to this post

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

    4865 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.