kriss/yii2-alert-notify

Yii2 Alert Notify

Maintainers

👁 kriss

Package info

github.com/krissss/yii2-alert-notify

Type:yii2-extension

pkg:composer/kriss/yii2-alert-notify

Statistics

Installs: 38

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1 2019-11-08 02:52 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT cb2b1a597a9907f647504ced1d6b46cd2ebb2c01

  • kriss <462679766.woop@qq.com>

extensionnotifyalertyii2

This package is auto-updated.

Last update: 2026-06-08 17:12:12 UTC


README

Yii2 Alert Notify

Installation

composer require kriss/yii2-alert-notify -vvv

Usage Ajax Notify

  1. Create a controller like: AjaxController, then add action:
public function actions()
{
 $actions = parent::actions();

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

 return $actions;
}
  1. Write generateNotifyInfo in controller, this is example:
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;
}
  1. Use Widget in View, like layouts/main.php
<?= AjaxNotifyWidget::widget() ?>
  1. After refresh browser, you will see:

👁 preview1

Ajax Notify generateInfo Result Description

Usage Flush Notify

  1. Use Widget in View, like layouts/main.php
<?= FlushNotifyWidget::widget() ?>
  1. Add flush message in controller or service:
Yii::$app->session->addFlash('success', 'Operate Success');
Yii::$app->session->addFlash('danger', 'Operate danger');
Yii::$app->session->addFlash('error', 'Operate error');
  1. After refresh browser, you will see:

👁 preview1