1. Go to this page and download the library: Download suver/yii2-notifications library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
suver / yii2-notifications example snippets
Notifications::get('news-add', 1) // Return new instance notification model from "news-add" template for user with id=1
->setParams(['newsLink' => Url::to(['/news-feed/default/' . $event->sender->id], true)]) // set parrams for replace "{{newsLink}}" => /news-feed/default/1
->send(); // send message.
// Set new message body
Notifications::get('news-add', 1)->setMessage($message)
// Set new message body & new subject
Notifications::get('news-add', 1)->setMessage($message)->setSubject($subject)
// Set new message body & new subject & hold over message
Notifications::get('news-add', 1)->setMessage($message)->setSubject($subject)->holdOver()
// Select "flash-notifications" channel & set new message body & new subject & hold over message
Notifications::get('news-add', 1)->setChannel('flash-notifications')->setMessage($message)->setSubject($subject)->holdOver()
// Send notifications for all user selected channel
// You must implements UserNotificationsInterface and return from getNotificationChannels() method channel array as ['email', 'flash-notifications', 'and', 'other', 'notify']
Notifications::get('news-add', 1)->sendUserChannels()
namespace suver\notifications;
use Yii;
use suver\notifications\models\Notifications as NotificationsModel;
/**
* Class Notification
* @package yii2-notifications
*/
class YouChannel implements ChannelInterface
{
public $class;
public $config;
public $init;
public function __construct($app, $config, $init) {
$this->config = $config;
$this->init = $init;
$app->components = [
// configure you needed components
];
}
public function getChannelName() {
return 'you-channel-name';
}
public function init($config) {
$this->config = $config;
}
public function send(NotificationsModel $object, $user) {
$subject = $object->getSubject();
$message = $object->getMessage();
Yii::$app->session->setFlash($this->init['key'], $subject . " | " . $message);
return true;
}
}
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.