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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Why is onBeforeWrite() called several times?


Go to End


3 Posts   1958 Views

Avatar
dompie

Community Member, 88 Posts

26 February 2011 at 3:00am

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.

Avatar
omarkohl

Community Member, 30 Posts

2 March 2011 at 1:11am

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?"

Avatar
Willr

Forum Moderator, 5523 Posts

2 March 2011 at 10:43pm

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.