PHPackages                             denisbespyatov/notifications - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. denisbespyatov/notifications

ActiveYii2-extension[Mail &amp; Notifications](/categories/mail)

denisbespyatov/notifications
============================

Notifications module for Yii2

1.0.0.1(1y ago)01PHPPHP &gt;=5.6

Since Oct 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/denisbespyatov/notifications)[ Packagist](https://packagist.org/packages/denisbespyatov/notifications)[ RSS](/packages/denisbespyatov-notifications/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

yii2-notifications
==================

[](#yii2-notifications)

This module provides a way to sending notifications across a variety of delivery channels, including mail, screen, SMS (via Nexmo), etc. Notifications may also be stored in a database so they may be displayed in your web interface.

Notifications are short messages that notify users of something that occurred in your application. For example, if you are writing a billing application, you might send an "Invoice Paid" notification to your users via the email and SMS channels.

 [![Yii2 Notifications Module](https://camo.githubusercontent.com/db88eb2ba6b662ff405346bfa7a99a39328d5e26e623df3d176e7962000c5d49/687474703a2f2f352e3138392e3135302e3134352f32313632313934375f31303135353639353031313035383337375f3635393333343639332e6a7067)](https://camo.githubusercontent.com/db88eb2ba6b662ff405346bfa7a99a39328d5e26e623df3d176e7962000c5d49/687474703a2f2f352e3138392e3135302e3134352f32313632313934375f31303135353639353031313035383337375f3635393333343639332e6a7067)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist denisbespyatov/notifications "*"

```

or add

```
"denisbespyatov/notifications": "*"
```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

Notifications is often used as an application module and configured in the application configuration like the following:

```
[
    'modules' => [
        'notifications' => [
            'class' => 'denisbespyatov\notifications\Module',
            'channels' => [
                'screen' => [
                    'class' => 'denisbespyatov\notifications\channels\ScreenChannel',
                ],
                'email' => [
                    'class' => 'denisbespyatov\notifications\channels\EmailChannel',
                    'message' => [
                        'from' => 'example@email.com'
                    ],
                ],
            ],
        ],
    ],
]
```

### Create A Notification

[](#create-a-notification)

Each notification is represented by a single class (typically stored in the app/notifications directory).

```
namespace app\notifications;

use Yii;
use denisbespyatov\notifications\Notification;

class AccountNotification extends Notification
{
    const KEY_NEW_ACCOUNT = 'new_account';

    const KEY_RESET_PASSWORD = 'reset_password';

    /**
     * @var \yii\web\User the user object
     */
    public $user;

    /**
     * @inheritdoc
     */
    public function getTitle(){
        switch($this->key){
            case self::KEY_NEW_ACCOUNT:
                return Yii::t('app', 'New account {user} created', ['user' => '#'.$this->user->id]);
            case self::KEY_RESET_PASSWORD:
                return Yii::t('app', 'Instructions to reset the password');
        }
    }

    /**
     * @inheritdoc
     */
    public function getRoute(){
        return ['/users/edit', 'id' => $this->user->id];
    }
}
```

### Send A Notification

[](#send-a-notification)

Once the notification is created, you can send it as following:

```
$user = User::findOne(123);

AccountNotification::create(AccountNotification::KEY_RESET_PASSWORD, ['user' => $user])->send();
```

### Specifying Delivery Channels

[](#specifying-delivery-channels)

Every notification class has a shouldSend($channel) method that determines on which type of keys and channels the notification will be delivered. In this example, the notification will be delivered in all channels except "screen" or with key "new\_account":

```
/**
 * Get the notification's delivery channels.
 * @return boolean
 */
public function shouldSend($channel)
{
    if($channel->id == 'screen'){
        if(!in_array($this->key, [self::KEY_NEW_ACCOUNT])){
            return false;
        }
    }
    return true;
}
```

### Specifying The Send For Specific Channel

[](#specifying-the-send-for-specific-channel)

Every channel have a send method that receive a notification instance and define a way of that channel will send the notification. But you can override the send method by define toMail ("to" + \[Channel ID\]) in notification class. This example show how to do that:

```
/**
 * Override send to email channel
 *
 * @param $channel the email channel
 * @return void
 */
public function toEmail($channel){
    switch($this->key){
        case self::KEY_NEW_ACCOUNT:
            $subject = 'Welcome to MySite';
            $template = 'newAccount';
            break;
        case self::KEY_RESET_PASSWORD:
            $subject = 'Password reset for MySite';
            $template = 'resetPassword';
            break;
    }

    $message = $channel->mailer->compose($template, [
        'user' => $this->user,
        'notification' => $this,
    ]);
    Yii::configure($message, $channel->message);

    $message->setTo($this->user->email);
    $message->setSubject($subject);
    $message->send($channel->mailer);
}
```

### Custom Channels

[](#custom-channels)

This module have a some pre-built channels, but you may want to write your own channels to deliver notifications. To do that you need define a class that contains a send method:

```
namespace app\channels;

use denisbespyatov\notifications\Channel;
use denisbespyatov\notifications\Notification;

class VoiceChannel extends Channel
{
    /**
     * Send the given notification.
     *
     * @param Notification $notification
     * @return void
     */
    public function send(Notification $notification)
    {
        // use $notification->getTitle() ou $notification->getDescription();
        // Send your notification in this channel...
    }

}
```

You also should configure the channel in you application config:

```
[
    'modules' => [
        'notifications' => [
            'class' => 'denisbespyatov\notifications\Module',
            'channels' => [
                'voice' => [
                    'class' => 'app\channels\VoiceChannel',
                ],
                //...
            ],
        ],
    ],
]
```

### Screen Channel

[](#screen-channel)

This channel is used to show small notifications as above image preview. The notifications will stored in database, so before using this channel, you have to run its migrations scripts:

```
./yii migrate/up --migrationPath=vendor/denisbespyatov/notifications/migrations/
```

So you can call the Notifications widget in your app layout to show generated notifications:

```

    ...

```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

574d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4248476bf3b7b212047dc390c115d1d5c63a50ebd437d6ac0d323fe10babaa5e?d=identicon)[denisbespyatov](/maintainers/denisbespyatov)

---

Top Contributors

[![denisbespyatov](https://avatars.githubusercontent.com/u/60224716?v=4)](https://github.com/denisbespyatov "denisbespyatov (3 commits)")

---

Tags

yii2yii2-notificationsyii2-notifications-moduleyii2-manage-notifications

### Embed Badge

![Health badge](/badges/denisbespyatov-notifications/health.svg)

```
[![Health](https://phpackages.com/badges/denisbespyatov-notifications/health.svg)](https://phpackages.com/packages/denisbespyatov-notifications)
```

###  Alternatives

[webzop/yii2-notifications

Notifications module for Yii2

72111.6k1](/packages/webzop-yii2-notifications)[loveorigami/yii2-notification-wrapper

This module for renders a message from session flash (with ajax, pjax support and etc.)

77199.7k5](/packages/loveorigami-yii2-notification-wrapper)[nterms/yii2-mailqueue

Email queue component for yii2 that works with yii2-swiftmailer.

87129.2k2](/packages/nterms-yii2-mailqueue)[tuyakhov/yii2-notifications

The extension provides support for sending notifications across a variety of delivery channels, including mail, SMS, Slack etc. Notifications may also be stored in a database so they may be displayed in your web interface.

6735.5k2](/packages/tuyakhov-yii2-notifications)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
