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, biapar, Willr, Ingo, swaiba, simon_w

Email on alteration to dataobject in CMS?


Reply

4 Posts   341 Views

Avatar
JonC

2 November 2011 at 4:13pm Community Member, 8 Posts

Hi, guys.

Question: is it possible to have SS send an email to an email address stored in a particular DataObject when that DataObject is altered and then saved in the CMS?

Avatar
Devlin

2 November 2011 at 9:17pm Community Member, 215 Posts

class MyDO extends DataObject {
   function onBeforeWrite() {
      parent::onBeforeWrite();
      
      $email = new Email();
      $email->sendPlain();
   }
}

http://doc.silverstripe.org/sapphire/en/topics/datamodel

Avatar
JonC

3 November 2011 at 7:51pm Community Member, 8 Posts

Thanks!

Further refinement: is it possible to have it send that email only when a certain specific database field is changed?

Avatar
swaiba

3 November 2011 at 11:39pm Forum Moderator, 1796 Posts

yes, check out this method...
http://api.silverstripe.org/2.3/sapphire/model/DataObject.html#methodgetChangedFields