如何在Cakephp 3中创建警报通知

时间:2018-06-13 18:15:13

标签: cakephp

我正在使用此插件完整日历来创建一些事件

https://github.com/curtisblack2004/CakePHP-Full-Calendar-Plugin

我还添加了每周发送消息的Cron Shell

我的问题现在我想要例如每个新事件都发送一条通知消息 通过电子邮件还通知用户已创建事件 这意味着我的EventController

在我的添加功能中更准确

EventsController

public function add()
{
$event = $this->Events->newEntity();
    if ($this->request->is('post')) {
        $event = $this->Events->patchEntity($event, $this->request->data);
        if ($this->Events->save($event)) {
            //function I need here to send mail
            $this->Flash->success(__('The event has been saved.'));
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error(__('The event could not be saved. Please, try again.'));
        }
    }
    $this->set('eventTypes', $this->Events->EventTypes->find('list'));
    $this->set(compact('event'));
    $this->set('_serialize', ['event']);
    $this->set('user_session', $this->request->session()->read('Auth.User'));
    $this->viewBuilder()->setLayout('user');
}

index.ctp

<li role="presentation" class="dropdown">
              <a href="javascript:;" class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false">
                <i class="fa fa-envelope-o"></i>
                <span class="badge bg-green">6</span>
              </a>
              <ul id="menu1" class="dropdown-menu list-unstyled msg_list" role="menu">

  •                 

  • 1 个答案:

    答案 0 :(得分:0)

    基本上,您的系统需要检查数据库中的状态以进行状态更改。

    在系统创建日历事件后,您必须将该记录保存在数据库中。基本上,您必须要求服务器获得响应。现在,您无需请求即可获得响应。这是通知的基本思想。

    • 错误的想法是通过ajax检查时间间隔。
    • 好主意可能是使用socket io(https://socket.io/)和Node.js

    我相信你找不到即插即用插件。