Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Why is onBeforeWrite() called several times?

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

Page: 1
Go to End
Author Topic: 898 Views
  • dompie
    Avatar
    Community Member
    88 Posts

    Why is onBeforeWrite() called several times? Link to this post

    this:

    some time ago I realized that SilverStripe calls multiple times the same function. E.g.
    Place a onBeforeWrite function to your Page class and put 'print('Hello World');' (or even mail()) in it and save.

    Examining the response in firebug will reveal 'Hello World' at least 2 times in the server response. Why? I saved only once, so it should be onBeforeWrite once too. When pressing save & publish, 'Hello World' appears 3 times in the response. Is this by Design? It looks like a waste of resources if it's executed twice, instead of once.

  • omarkohl
    Avatar
    Community Member
    30 Posts

    Re: Why is onBeforeWrite() called several times? Link to this post

    I have no answer to your question but the title of your thread is not very helpful if you want someone to answer your question ;-).

    How about "Why is onBeforeWrite() called several times?"

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Why is onBeforeWrite() called several times? Link to this post

    Examining the response in firebug will reveal 'Hello World' at least 2 times in the server response

    In your onBeforeWrite() you could log a backtrace. Looking at the backtrace you'll be able to work out whats calling it. I'm picking it'll be quite hard to avoid.

    898 Views
Page: 1
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.