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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Automatically update date field when changing another field value

Go to End

2 Posts   953 Views


Community Member, 22 Posts

20 July 2012 at 4:52pm

Hi, I want to keep a record of when a field was last changed. I have a site where I want to "feature" an object (it's a publication) every couple of weeks on the front page of the site. I plan on having a group of publications that are worth featuring and rotate them. I will either flag all of the featurable publication records and have one randomly appear - if anyone can tell me how to do this I would be grateful - or I will manually change the flag on one of the papers every couple of weeks. This, I know I can do! If I manually change the flag, I optimally want to have a date field that will change to the current date every time I change the flag to "on", so I can see when the last time it was featured was. I can't figure out how to do it - can anyone help?


Forum Moderator, 1899 Posts

21 July 2012 at 12:09am


something like this might help...

public function onAfterWrite() {
	$arrChanged = $this->getChangedFields(true,1);
	//Log $arrChanged - this structure contains all information about changes made in the last write store this information where you like