[英]Symfony2 kernel.response Event after controller annotations are executed
In order to modify a response cache control header I use a kernel.response event. 为了修改响应缓存控制标头,我使用了kernel.response事件。 But when my listener gets called the controllers @cache annotation is not yet executed.
但是当我的监听器被调用时,控制器@cache注释尚未执行。 How can I make sure that my listener gets called after all controller annotations are executed?
如何确保在执行所有控制器批注之后调用我的侦听器?
You can change the order of listeners on the same event by setting priority. 您可以通过设置优先级来更改同一事件上侦听器的顺序。 As you can see in the
HttpCacheListener
of the SensioFrameworkExtraBundle, there is no explicit priority set. 如您在SensioFrameworkExtraBundle的
HttpCacheListener
中看到的,没有显式设置优先级。 That means it has the default priority of 0
. 这意味着它的默认优先级为
0
。 So you can set your priority to any number higher than 0
(I recommend 10
or the like) to execute it before: 因此,您可以将优先级设置为大于
0
任何数字(我建议使用10
或类似的数字)来执行以下操作:
services:
my_cache_listener:
class: ...
tags:
- { name: kernel.event_listener, event: kernel.response, priority: 10 }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.