是否可以从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);
}
}
}
?>
谢谢!