【发布时间】:2016-09-06 00:35:57
【问题描述】:
我正在努力让 CakePHP (v3.x) 事件中的最终链接正常工作。在我的 Controler add 方法中,我有公共功能
add()
{
$event = new Event('Model.Comment.created', $this, [
'comment' => $comment
]);
$this->eventManager()->dispatch($event);
}
并设置我的监听器类:
namespace App\Event;
use Cake\Log\Log;
use Cake\Event\EventListener;
class CommentListener implements EventListener {
public function implementedEvents() {
return array(
'Model.Comment.created' => 'updatePostLog',
);
}
public function updatePostLog($event, $entity, $options) {
Log::write(
'info',
'A new comment was published with id: ' . $event->data['id']);
}
}
但无法正确设置侦听器,尤其是在我的应用知道我的 CommentListener 类存在的情况下。
【问题讨论】:
-
是否显示一些错误或警告?
-
不,运行,但我什么也没做,我知道我错过了将两者联系在一起的部分,我不确定它是如何实现的。
-
查看文档:book.cakephp.org/3.0/en/core-libraries/… 我很困惑这些行的去向: // 将 UserStatistic 对象附加到订单的事件管理器 $statistics = new UserStatistic(); $this->Orders->eventManager()->on($statistics);
标签: php cakephp cakephp-3.0