Skip to content

Instantly share code, notes, and snippets.

@ovicko
Last active May 19, 2021 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovicko/75e525c8784cb865c5be66cff4dac7a0 to your computer and use it in GitHub Desktop.
Save ovicko/75e525c8784cb865c5be66cff4dac7a0 to your computer and use it in GitHub Desktop.
Attach the event handler in the init method of your ActiveRecord.
<?php
class Records extends \yii\db\ActiveRecord
{
const EVENT_SEND_EMAIL_UPDATE = 'send-email-to-users';
public function init()
{
// first parameter is the name of the event and second is the handler. 
// sendMail method from $this class.
$this->on(self::EVENT_SEND_EMAIL_UPDATE, [$this, 'sendMail']);
parent::init(); // DON'T Forget to call the parent method.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment