PHP code example of hossein142001 / yii2-notification
1. Go to this page and download the library: Download hossein142001/yii2-notification 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/ */
hossein142001 / yii2-notification example snippets
use hossein142001\notification\components\Notification;
/* @var \hossein142001\notification\Module $sender */
$sender = Yii::$app->getModule('notification');
$notification = new Notification([
'from' => [\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'],
'to' => $deal['userSeller']['email'], // string or array
'toId' => $deal['userSeller']['id'], // string or array
'phone' => $deal['userSeller']['phone_number'], // string or array
'subject' => "\"{$deal['userBuyer']['nameForOut']}\" offers you a deal for \"{$deal['ads']['product']->getName()}\"",
'token' => 'TOKEN',
'content' => "",
'params' => [
'productName' => $deal['ads']['product']->getName(),
'avatar' => $deal['userBuyer']->avatarFile,
'fromUserName' => $deal['userBuyer']['nameForOut'],
],
'view' => ['html' => 'Request-html', 'text' => 'Request-text'],
'path' => '@common/mail/deal',
'notify' => ['growl', 'A confirmation email has been sent to your email'],
'callback' => function(Provider $provider, $status){
// Here you can process the response from notification providers
}
]);
$sender->sendEvent($notification);
use yii\base\Event;
use hossein142001\notification\components\Notification;
$event = new Notification(['params' => [
'from' => [\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'],
'to' => $user->email,
'subject' => 'registration on the site ' . \Yii::$app->name,
'emailView' => ['html' => 'signUp-html', 'text' => 'signUp-text'],
'user' => $user,
'phone' => $user->phone_number,
'notify' => ['growl', 'A confirmation email has been sent to your email'],
]]);
Notification::trigger(self::className(),'Signup', $event);
$notification = new Notification([
'from' => [\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'],
'to' => $deal['userSeller']['email'], // string or array
'toId' => $deal['userSeller']['id'], // string or array
'phone' => $deal['userSeller']['phone_number'], // string or array
'subject' => "\"{$deal['userBuyer']['nameForOut']}\" offers you a deal for \"{$deal['ads']['product']->getName()}\"",
'token' => 'TOKEN',
'content' => "",
'params' => [
'productName' => $deal['ads']['product']->getName(),
'avatar' => $deal['userBuyer']->avatarFile,
'fromUserName' => $deal['userBuyer']['nameForOut'],
],
'view' => ['html' => 'Request-html', 'text' => 'Request-text'],
'path' => '@common/mail/deal',
'notify' => ['growl', 'A confirmation email has been sent to your email'],
'callback' => function(Provider $provider, $status){
// Here you can process the response from notification providers
}
]);
Notification::trigger(self::className(),'Request', $notification);