从Cakephp 3.X组件触发事件

时间:2017-08-09 17:34:17

标签: cakephp cakephp-3.0 cakephp-3.x cakephp-3.2 cakephp-3.4

是否可以从Cakephp 3.x组件触发事件?

以下代码返回以下错误:

"致命错误:在第190行和第34行调用未定义的方法MyPlugin \ Controller \ Component \ MyNewComponent :: eventManager();

<?php
namespace MyPlugin\Controller\Component;

use Cake\Controller\Component;
use Cake\Event\Event;

class MyNewComponent extends Component {

    public function myComponentMethod(){
        ...
        if(1 == 1) {
            $user = $this->request->session()->read('Auth.User');
            $event = new Event('Component.Aws.registrar', $this, [
                'username' => $user['username'],
                'user_id' => $user['id']
                    ]);
            $this->eventManager()->dispatch($event);
        }
    }
}
?>

谢谢!

0 个答案:

没有答案