Php 在Symfony 1.4中的每个操作后执行代码
我知道我们可以在Symfony中的每个操作之前使用过滤器创建代码,但是在每个操作完成之后呢?PostExecute方法?PostExecute方法在每个操作调用结束时执行。Php 在Symfony 1.4中的每个操作后执行代码,php,symfony1,Php,Symfony1,我知道我们可以在Symfony中的每个操作之前使用过滤器创建代码,但是在每个操作完成之后呢?PostExecute方法?PostExecute方法在每个操作调用结束时执行。 以下是您可以使用过滤器在执行后执行代码的方法: class myFilter extends sfFilter { public function execute($filterChain) { // Code that is executed before the action is execu
以下是您可以使用过滤器在执行后执行代码的方法:
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
}
}
这是因为Symfony中的完整执行是一个大的“过滤链”。。。如果仔细查看过滤器.yml
,您将看到首先调用呈现
过滤器,然后调用安全
过滤器、缓存
过滤器,最后调用执行
过滤器。
执行过滤器是实际执行请求(调用控制器和所有内容)的过滤器
为了说明这一点:缓存过滤器将在进入链之前检查缓存中是否有有效的输出,并返回该输出。如果现在它将执行链中的下一个过滤器,当它返回时,存储输出,以便后续请求可以使用缓存。您必须在action类中添加此方法:
public function postExecute()
{
// do something
}
这适用于模块中的每个操作,而不是应用程序中的每个操作。