Notifier is used as an application component and configured in the application configuration like the following:
[
'components' => [
'notifier' => [
'class' => \kaswell\notification\Notifier::class,
'channels' => [
'telegram' => [
'class' => \kaswell\notification\channels\TelegramChannel::class,
'botToken' => '...'
],
'mail' => [
'class' => \kaswell\notification\channels\MailChannel::class,
'from' => 'no-reply@example.com'
],
'database' => [
'class' => \kaswell\notification\channels\ActiveRecordChannel::class
]
],
],
],
]
Add NotificationBehavior to any model or active record
public function behaviors()
{
return [
...
[
'class' => ActiveRecordBehavior::class,
'excludedAttributes' => ['updated_at'],
],
...
];
}
Migrations
yii migrate --migrationPath=@vendor/kaswell/yii-notifications/src/migrations
or
'controllerMap' => [
...
'migrate' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationNamespaces' => [
'kaswell\notification\migrations',
],
],
...
],