Yii2 高级发送通知给管理员

时间:2021-06-29 22:10:39

标签: notifications yii2 yii2-advanced-app behavior rbac

我正在开发一个 yii2 项目,用户要求出租车,他们的汽车请求应该发送给管理员,管理员接受或拒绝他们的请求。为此,我在后端创建了一个组件文件夹并在其中放置了一个通知行为:

    <?php

namespace backend\components;
use Yii;
use backend\controllers\carrequests;
use yii\base\Behavior;
use yii\db\ActiveRecord;


class NotificationBehavior extends Behavior
{

  
  public function events()
  {
    return [
      ActiveRecord::EVENT_AFTER_INSERT => 'afterInsert',
      ActiveRecord::EVENT_AFTER_UPDATE => 'afterUpdate',
    ];
  }


  public function afterInsert($event)
  {
    // check the 'id' (name) of the action
    if (Yii::$app->controller->action->id === 'create') {
      // send email to administrator 'user performed insert'
    }
  }

 
  public function afterUpdate($event)
  {
    if (Yii::$app->controller->action->id === 'update') {
      // send email to administrator 'user performed update'
    }
  }

}


?>

然后我有一个我使用的表单使用 backend\components\NotificationBehavior;在其中,但管理员没有收到用户的汽车请求。我感谢一点帮助我不知道我做错了什么。我正在使用 rbac。

0 个答案:

没有答案