Hello UncleCheese, could you explain why we shall use static class variable, not object variable??
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.
- Previous 10 entries
- 1
- Page 22(current)
I know that this is an old thread, but as I ended up here from Google without seeing other threads in the search results, I'll use this thread.
I knew I had found a solution to this problem earlier and now that I searched for it again I went through my existing code after first searching from Google, and I found it again:
public function onBeforeWrite()
{
if ($this->isChanged('ID',2)) //This is a new object
{
}
}
This checks if there is a real data change in the ID field (= triggers when the record is created, not anymore at the second call).
I think this is a little bit cleaner way to solve this problem than creating a static variable. Well, years have passed since the UncleCheese's answer, so perhaps this method was not available back then :).
- Previous 10 entries
- 1
- Page 22(current)