背景: 我想使用来自调用事件调度程序的函数的事件侦听器中的数据。从我所看到的事件调度程序只返回GenericEvent对象。
主捆绑包是调用调度程序的地方。
MainBundleController.php
public function mainBundle() {
$this->getContainer()->get('event_dispatcher')->addListener('my_test_event', new GenericEvent($object))
// Is it possible to use the data from $anotherBundleListener
}
AnotherBundle / services.yml
another_bundle.listener:
class: ..../AnotherBundleEventService
tags:
- {name: kernel.event_listener, event: my_test_event, method: anotherBundleListener}
AnotherBundleEventService.php
public function anotherBundleListener(GenericEvent $event) {
//Do amazing things
return $somethingAmazing
}
事件监听器和调度程序工作唯一的问题是我想在调用调度程序的函数中使用监听器中的数据。
如果还有其他方式,请告诉我。
答案 0 :(得分:0)
我在这里找到了解决方案http://symfony.com/doc/2.8/event_dispatcher/method_behavior.html
{{1}}