21301 Posts in 5735 Topics by 2603 members
General Questions
SilverStripe Forums » General Questions » Automatically update date field when changing another field value
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 202 Views |
-
Automatically update date field when changing another field value

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?
-
Re: Automatically update date field when changing another field value

21 July 2012 at 12:09am
Hi,
something like this might help...
public function onAfterWrite() {
parent::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
}
| 202 Views | ||
|
Page:
1
|
Go to Top |


