Skip to content

Instantly share code, notes, and snippets.

@pebriana
Created January 27, 2016 14:54
Show Gist options
  • Select an option

  • Save pebriana/9cb1512661a617a7ca0f to your computer and use it in GitHub Desktop.

Select an option

Save pebriana/9cb1512661a617a7ca0f to your computer and use it in GitHub Desktop.
yii2 after save
public function afterSave($insert, $changedAttributes)
{
if (($this->scenario == 'user' || $this->scenario == 'guest') && $this->isNewRecord)
\Yii::$app->mailer->compose('new_comment', ['model' => $this])
->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])
->setTo(Email::getByGroup(Email::COMMENTS))
->setSubject('Some subject')
->send();
parent::afterSave($insert, $changedAttributes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment