我知道我们可以在Symfony中的每个操作之前使用过滤器来创建代码,但是在每个操作完成之后呢?一个PostExecute方法?
Gra*_*rck 10
您也可以使用过滤器在执行后执行代码:
class myFilter extends sfFilter {
public function execute($filterChain) {
// Code that is executed before the action is executed
$filterChain->execute();
// Code that is executed after the action has been executed
}
}
Run Code Online (Sandbox Code Playgroud)
这是因为Symfony中的完整执行是一个很大的"过滤链"...如果你仔细观察你filters.yml,你会看到首先rendering调用过滤器,然后是security过滤器,cache过滤器,最后是execution过滤器.执行过滤器是实际执行请求的过滤器(调用控制器和所有内容).
为了说明这一点:缓存过滤器在下行之前,检查缓存中是否有可用的有效输出,然后返回.如果现在它将执行链中的下一个过滤器,并且当它返回时,存储输出,以便后续请求可以使用缓存.