Jump to:

23453 Posts in 18904 Topics by 2877 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 471 Views
  • Bronwyn
    Avatar
    Community Member
    16 Posts

    Automatically update date field when changing another field value Link to this post

    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?

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Automatically update date field when changing another field value Link to this post

    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
    }

    471 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.