Reputation: 7024
I know that we can use filters to create code before every action in Symfony, but what about after every action has been made? a PostExecute method?
Upvotes: 5
Views: 2853
Reputation: 1279
You have to add this method in action class:
public function postExecute()
{
// do something
}
Upvotes: 2
Reputation: 4506
You can use filters to execute code after execution as well:
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
}
}
This is because the complete execution in Symfony is one big "filter chain"... If you look closely at your filters.yml
, you'll see that first the rendering
filter is called, then the security
filter, the cache
filter and finally the execution
filter.
The execution filter is the filter which actually executes the request (calls the controller and everything).
To illustrate this: the cache filter will, before going down the chain, check if a valid output is available in the cache, and return that. If now it will execute the next filter in the chain, and when it returns, store the output so subsequent requests can use the cache.
Upvotes: 10
Reputation: 1988
the postExecute method is executed at the end of each action call.
Here is the documentation
Upvotes: 1