Last active
May 19, 2021 11:09
-
-
Save ovicko/f907d599a60ea89649f36f6a9d2a6b5d to your computer and use it in GitHub Desktop.
Add sendMail method to ActiveRecord class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Records extends \yii\db\ActiveRecord | |
{ | |
const EVENT_SEND_EMAIL_UPDATE = 'send-email-to-users'; | |
public function init() { | |
$this->on(self::EVENT_SEND_EMAIL_UPDATE, [$this, 'sendMail']); | |
//use this if you want to add custom data to your events | |
$this->on(self::EVENT_SEND_EMAIL_UPDATE, [$this, 'sendMail'],['Email 1','Email 2','Email 3']); | |
parent::init(); | |
} | |
public function sendMail($event) { | |
//if you had attached some data you can use this to get the event data | |
$customData = $event->data; | |
//send email to subscribers | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment