Run code after every action in Symfony 1.4

I know that we can use filters to create code before each action in Symfony, but what about after each action? PostExecute method?

+4
source share
3 answers

You can also use filters to execute code after execution:

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 full execution in Symfony is one big "filter chain" ... If you look closely at your filters.yml , you will see that the rendering filter is called first, then the security filter, the cache filter, and finally execution filter. The execution filter is the filter that actually executes the request (invokes the controller and that's it).

To illustrate this: the cache filter, before descending the chain, checks to see if a valid output in the cache is available, and return it. If he now executes the next filter in the chain, and when he returns, save the output so that subsequent requests can use the cache.

+9
source

You must add this method to the action class:

  public function postExecute() { // do something } 
+2
source

The postExecute method is executed at the end of each action call.
Here is the documentation

+1
source

Source: https://habr.com/ru/post/1382492/


All Articles