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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With