PHPackages                             cb-techservices/yii2-notification-system - 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. cb-techservices/yii2-notification-system

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

cb-techservices/yii2-notification-system
========================================

Yii2 extension which provides a fully functional notification system with customizable UI.

46.2k↓62.7%5[2 issues](https://github.com/cb-techservices/yii2-notification-system/issues)PHP

Since Apr 20Pushed 7y ago2 watchersCompare

[ Source](https://github.com/cb-techservices/yii2-notification-system)[ Packagist](https://packagist.org/packages/cb-techservices/yii2-notification-system)[ RSS](/packages/cb-techservices-yii2-notification-system/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 Notification System
========================

[](#yii2-notification-system)

This Yii2 extension provides a fully functional notification system backed with ActiveRecord and a customizable UI.

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

[](#installation)

##### Composer

[](#composer)

```
php composer.phar require cb-techservices/yii2-notification-system "*"
```

or add

```
"cb-techservices/yii2-notification-system": "*"
```

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

Configuration
-------------

[](#configuration)

Before using this module, you have to run its migrations scripts. This will add the notification table to your database.

Run this command from the root of your Yii project:

```
./yii migrate/up --migrationPath=vendor/cb-techservices/yii2-notification-system/migrations/
```

Add the following to the `modules` section of your Yii project config.

```
'modules'=>[
    'notifications' => [
        'class' => 'cbtech\notification_system\NotificationSystemModule',
        //The controller's namespace for where to find the Controller actions.
        //You may use the default NotificationsController provided or create your own custom controller.
        'controllerNamespace' => 'cbtech\notification_system\controllers',
        // Point this to your own Notification class
        // See the "Declaring your notifications" section below
        'notificationClass' => 'common\models\Notification',
        // Allow to have notification with same (user_id, key, key_id)
        // Default to FALSE
        'allowDuplicate' => true,
        // Allow custom date formatting in database
        'dbDateFormat' => 'Y-m-d H:i:s',
		// This callable should return your logged in user Id
        'userId' => function() {
            return \Yii::$app->user->id;
        },
        'expirationTime'=>0
    ],
],
```

### Module Parameters

[](#module-parameters)

ParameterTypeDescriptionDefaultclassStringThe required class path to the NotificationSystemModule'cbtech\\notification\_system\\NotificationSystemModule'controllerNamespaceStringThe controller's namespace for where to find the Controller actions. You may use the default NotificationsController provided or create your own custom controller.'cbtech\\notification\_system\\controllers'notificationClassStringPoint this to your own Notification class. See the "Declaring your notifications" section below.'common\\models\\Notification'allowDuplicateBooleanAllow to have notifications with the same user\_id, key, key\_idfalsedbDateFormatStringAllows custom date formatting in databse'Y-m-d H:i:s'userIdcallable/integerThis callable should return your logged in user Id`function() { return \Yii::$app->user->id; }`### Declaring your notifications

[](#declaring-your-notifications)

Your custom Notification class must **extend** `cbtech\notification_system\models\NotificationBase`

An example is provided in [examples/Notification.php](examples/Notification.php)

Usage
-----

[](#usage)

### Triggering a notification

[](#triggering-a-notification)

```
// A connection request made by a user to the $recipient_id
Notification::notify(Notification::KEY_NEW_CONNECTION_REQUEST, $recipient_id, $connectionRequest->id);

// You may also use the following static methods to set the notification type:
Notification::warning(Notification::KEY_NEW_MESSAGE, $recipient_id, $message->id);
Notification::success(Notification::ORDER_PLACED, $admin_id, $order->id);
Notification::error(Notification::KEY_NO_DISK_SPACE, $admin_id);
```

### Listening and showing notifications in the UI

[](#listening-and-showing-notifications-in-the-ui)

This extension comes with a `NotificationsWidget` that is used to regularly poll the server for new notifications.

### Widget Parameters

[](#widget-parameters)

ParameterTypeDescriptionDefaultpollUrlStringThe URL for the poll() for new notifications controller action'/notifications/notifications/poll'markAsReadUrlStringThe URL for the controller action that marks an individual notification as read'/notifications/notifications/read'markAsUnreadUrlStringThe URL for the controller action that marks an individual notification as unread'/notifications/notifications/unread'flashUrlStringThe URL for the controller action that marks an individual notification as having been flashed'/notifications/notifications/flash'readAllUrlStringThe URL for the controller action that marks all notifications as read'/notifications/notifications/read-all'unreadAllUrlStringThe URL for the controller action that marks all notifications as unread'/notifications/notifications/unread-all'delayIntegerThe time to leave the notification shown on screen5000pollIntervalIntegerThe delay in milliseconds between polls5000xhrTimeoutIntegerThe XHR request timeout in milliseconds2000countersArrayAn array of jQuery selectors to update with the current notifications count\[\]markAllReadSelectorStringThe jQuery selector for the Mark All as Read buttonnullmarkAllUnreadSelectorStringThe jQuery selector for the Mark All as Unread buttonnullviewAllSelectorStringThe jQuery selector for your UI element that will holds the notification listnullviewUnreadSelectorStringThe jQuery selector for the View Unread buttonnullheaderSelectorStringThe jQuery selector for the Notifications header viewnullheaderTemplateStringThe header HTML template. You can provide your own HTML structure and use the following variables: `{title}`,`{readAllId}`,`{unreadAllId}`See default example below.headerTitleStringThe header title string"Notifications"listSelectorStringThe jQuery selector for the View All buttonnulllistItemTemplateStringThe list item HTML template. You can provide your own HTML structure and use the following variables: `{id}`,`{title}`,`{body}`,`{read}`,`{unread}`,`{timeago}`,`{footer}`See default example below.### Widget Usage

[](#widget-usage)

Below is an example of the widget with all possible parameters. Optional values are indicated. This should be added at the top of your main layout template.

```
NotificationsWidget::widget([
    'pollUrl' => '/notifications/notifications/poll', //Optional, default value
    'markAsReadUrl' => '/notifications/notifications/read', //Optional, default value
    'markAsUnreadUrl' => '/notifications/notifications/unread', //Optional, default value
    'flashUrl' => '/notifications/notifications/flash', //Optional, default value
    'readAllUrl' => '/notifications/notifications/read-all', //Optional, default value
    'unreadAllUrl' => '/notifications/notifications/unread-all', //Optional, default value
    'clientOptions' => [
        'location' => 'tr',
    ],
    'delay' => 5000,
	'xhrTimeout' => 2000,
    'pollInterval' => 5000,
    'counters' => [
        '.notifications-header-count',
        '.notifications-icon-count'
    ],
    'markAllReadSelector' => '#notification-read-all',
    'markAllUnreadSelector' => '#notification-unread-all',
    'listSelector' => '#notifications',
    'viewAllSelector' => '#viewAll',
    'viewUnreadSelector' => '#viewUnread',
    'headerSelector' => '#notifications-header',
    'headerTitle' => 'Notifications',
    'headerTemplate' =>
        '' .
            '{title}' .
            'Read' .
            'Unread' .
            'Mark All as ' .
        '', //Optional, default value
    'listItemTemplate' =>
        '' .
            '' .
                '{title}' .
                '{body}' .
            '' .
            '' .
                '{read}{unread}' .
            '' .
            '' .
            '' .
                '{timeago}' .
            '' .
            '' .
                '{footer}' .
            '' .
            '' .
        '', //Optional, default value
]);
```

If you have provided a value for the `headerSelector` and/or the `listItemTemplate` you can include the notifications list view by adding the following to your navbar:

```
$menuItems[] = '

                        0

                            View All /
                            View Unread

                ';
```

#### Notifications List View

[](#notifications-list-view)

[![Notifications list view](https://raw.githubusercontent.com/cb-techservices/yii2-notification-system/master/images/NotificationsListView.png)](https://raw.githubusercontent.com/cb-techservices/yii2-notification-system/master/images/NotificationsListView.png)

#### Tostr Notification

[](#tostr-notification)

[![Toastr notification](https://raw.githubusercontent.com/cb-techservices/yii2-notification-system/master/images/ToastrNotification.png)](https://raw.githubusercontent.com/cb-techservices/yii2-notification-system/master/images/ToastrNotification.png)

Contributors
------------

[](#contributors)

Carl Burnstein

Credits
-------

[](#credits)

Inspired by [machour/yii2-notifications](https://github.com/machour/yii2-notifications)
Uses [CodeSeven/toastr](https://github.com/CodeSeven/toastr)

License
-------

[](#license)

Yii2 Notification System is licensed under MIT license -
Copyright (c) 2018 CB Tech Services

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity38

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10040482?v=4)[Carl Burnstein](/maintainers/carlb0329)[@carlb0329](https://github.com/carlb0329)

---

Top Contributors

[![carlb0329](https://avatars.githubusercontent.com/u/10040482?v=4)](https://github.com/carlb0329 "carlb0329 (39 commits)")

---

Tags

activerecordjavacsriptjquerynotificationnotification-systemphpyii2yii2-extensionyii2-notificationyii2-widgets

### Embed Badge

![Health badge](/badges/cb-techservices-yii2-notification-system/health.svg)

```
[![Health](https://phpackages.com/badges/cb-techservices-yii2-notification-system/health.svg)](https://phpackages.com/packages/cb-techservices-yii2-notification-system)
```

###  Alternatives

[maize-tech/laravel-email-domain-rule

Laravel Email Domain Rule

612.0k](/packages/maize-tech-laravel-email-domain-rule)[sarfraznawaz2005/noty

Laravel package to incorporate noty flash notifications into laravel.

324.5k](/packages/sarfraznawaz2005-noty)

PHPackages © 2026

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