dongzhukuai8177 2016-06-15 04:59
浏览 21

观察事件然后触发一个函数,PHP

I need some help creating a function that listens for events and then does something everytime an event happens. For example in my application, users can add subscriptions that have due dates.

public function add()
{
    $subscription = $this->Subscriptions->newEntity();
    if ($this->request->is('post')) {
        $subscription = $this->Subscriptions->patchEntity($subscription, $this->request->data);
        if ($this->Subscriptions->save($subscription)) {
            $this->Flash->success(__('The subscription has been saved.'));
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error(__('The subscription could not be saved. Please, try again.'));
        }
    }
    $users = $this->Subscriptions->Users->find('list', ['limit' => 200]);
    $this->set(compact('subscription', 'users'));
    $this->set('_serialize', ['subscription']);
}

Everytime a user adds a subscription, I want my web server to be watching the current date and if there are subscriptions for that due date I want it to fire a function such as echoing out some data. I was thinking of trying and creating an array that holds the subscriptions ID in the database and the due date and iterating over that array over and over again but that would pose some problems it being an infinite loop. Any ideas on how to implement something like this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥15 Python3.5 相关代码写作
    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像