2011-11-22 61 views

回答

1

postExecute方法在每个动作调用结束时执行。
这里是documentation

+0

这是一个模块中的每一个动作,而不是在一个应用程序。 – greg0ire

9

您可以使用过滤器执行后,执行代码,以及:

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的完整的执行是一个大的“过滤器链” ......如果你看看在您的filters.yml处,您会看到首先调用了rendering过滤器,然后是security过滤器,cache过滤器,最后是execution过滤器。 执行过滤器是实际执行请求的过滤器(调用控制器和所有内容)。

为了说明这一点:缓存过滤器将在下链之前检查缓存中是否有可用输出,并返回该缓存。如果现在它将执行链中的下一个过滤器,并在返回时存储输出,以便后续请求可以使用高速缓存。

2

你必须在动作类中添加这个方法:

public function postExecute() 
    { 
    // do something 
    } 
相关问题