I am trying to have an email sent every time a page is published. I am thinking of using onBeforePublish() for that.
To test it, I created a new page class :
class PageEmail extends Page {
function onBeforePublish() {
parent::onBeforePublish();
$subject = 'Page published '.$this->Title;
$email = new Email();
$email->setTo("myemail@yahoo.com");
$email->setFrom( Email::getAdminEmail());
$email->setSubject($subject);
$email->send();
}
}
When I try to "publish" a page of this type , I get the error message :
Error: Uncaught Exception: Object->__call(): the method 'onbeforepublish' does not exist on 'PageEmail'
At line 724 in /public_html/mydomain/silverstripe/sapphire/core/Object.php
Note that if I replace "onBeforePublish" with "onBeforeWrite" in the class definition, I get the email *twice* even though the function is not in page.php.
I also noticed that the function name in the error message is all in lower cases but I don't know if this is relevant.
I am obviously doing something wrong. Could you please point me in the right direction? ( I run version 2.4 of SilverStripe )
Thank you.