Download the PHP package dvamigos/yii2-notifications without Composer

On this page you can find all versions of the php package dvamigos/yii2-notifications. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-notifications

yii2-notifications

Notification system for Yii 2+

Usage

Default storage is your database. For that you need to insert migrations from src/migrations folder.

To insert those migrations you need to run migration command:

This will create notification table in your database. If you don't plan to store your notifications in database then this step is not necessary.

Add notification component configuration in your application config:

Then in your code you can push notifications directly using:

This will save the notification for current logged in user.

Notification types

You can define arbitrary number of types for your notification to store as much as data per notification as needed.

Below is an example of a notification having a title and a message.

Field {username} will be replaced from data passed to notification on its creation.

To pass data just use:

You do not have to always pass every necessary key into data. If you do not pass required key it's value will be taken from 'default' of that notification.

You can also use this array to pass any arbitrary information which can be serialized into JSON string, effectively allowing you to store any required data in order to display or use your notification.

Using in models/controllers/components

You can use PushNotification, UpdateNotification or ReplaceNotification classes inside your every component which has events() function.

To include events() function use EventListAwareTrait.

For example to set it inside a model you can define following:

Types can be resolved later using:

If you wish to use Behavior approach, that is also available via NotificationBehavior class.

To use that class you can simply add in your model/component which supports behaviors:

If you want to encapsulate your own logic, then extending \dvamigos\Yii2\Notifications\events\PushNotification with your own class is also a possibility.

Example:

Then you can add your notification simply as:

Multiple targets

You can define multiple targets when sending notifications effectively allowing you push notifications on phone devices, database, etc at the same time.

Your default target is database but you can define your own using:

Note

Please not that Android and iOS targets are WIP and not completely tested and might not work properly.

Then using above configuration, when calling:

You will send notification to database, your user's android device and ios device.

You can switch targets at any time using:

Please note that you should use popTarget() to restore old behavior. Example:

You can call specific target using:

Or you can execute command on specific targets using forTargets()

Token retrieval

Since some targets require additional token data for sending notification you can implement your own token retrieval logic based on which target needs which token.

Token retriever can be a callable closure:

tokenRetriever callable will be called every time token is required for sending.

tokenRetriever can also be a class which implements dvamigos\Yii2\Notifications\TokenRetrievalInterface.

Class:

Configuration:

Displaying notifications

You can use NotificationList widget to display your notifications.

Please note that depending on your use case you will need to configure this widget to suit your needs. This widget assumes that your component name is notification although you can pass a different name during widget creation.

You need to specify template for your notifications using this widget.

Example of a simple list where notifications are defined as.

Custom sections are also supported. And you can define them as:

Please refer to NotificationList documentation in the code for more information on what is available.

Best practice is to extend this NotificationList widget with your own and implement this functionality based on needs for your own project.


All versions of yii2-notifications with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
yiisoft/yii2 Version 2.0.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package dvamigos/yii2-notifications contains the following files

Loading the files please wait ....