Download the PHP package denisbespyatov/notifications without Composer
On this page you can find all versions of the php package denisbespyatov/notifications. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download denisbespyatov/notifications
More information about denisbespyatov/notifications
Files in denisbespyatov/notifications
Informations about the package 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.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json
file.
Usage
Notifications is often used as an application module and configured in the application configuration like the following:
Create A Notification
Each notification is represented by a single class (typically stored in the app/notifications directory).
Send A Notification
Once the notification is created, you can send it as following:
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":
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:
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:
You also should configure the channel in you application config:
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:
So you can call the Notifications widget in your app layout to show generated notifications: