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.

Data Model Questions /

Why is onBeforeWrite() called several times?


Reply


3 Posts   923 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, 5513 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.