PHP code example of kriss / yii2-alert-notify

1. Go to this page and download the library: Download kriss/yii2-alert-notify 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/ */

    

kriss / yii2-alert-notify example snippets


public function actions()
{
    $actions = parent::actions();

    $actions['notify'] = [
        'class' => AjaxNotifyAction::class,
        'generateInfo' => 'generateNotifyInfo',
    ];

    return $actions;
}

public function generateNotifyInfo($from)
{
    $info = [];
    // get info from db or other storage
    // example
    if (random_int(0, 999) > 300) {
        $info[] = [
            'notifyOptions' => [
                'message' => date('H:i:s') . ':Has New Message',
                'url' => Url::to(['site/index']),
                'target' => '_self',
            ],
            'notifySettings' => [
                'delay' => 0,
                'type' => 'info',
                'offset' => [
                    'x' => 20,
                    'y' => 70,
                ],
            ],
            'audioConfig' => [
                'url' => Yii::getAlias('@web/audio/sound1.mp3'),
                'count' => 1,
                'delay' => 1000,
            ],
        ];
    }
    // example End
    return $info;
}

Yii::$app->session->addFlash('success', 'Operate Success');
Yii::$app->session->addFlash('danger', 'Operate danger');
Yii::$app->session->addFlash('error', 'Operate error');
html
<?= AjaxNotifyWidget::widget() 
html
<?= FlushNotifyWidget::widget()