Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute code after every action in Symfony 1.4

Tags:

php

symfony1

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?

like image 519
vinnylinux Avatar asked Nov 22 '11 13:11

vinnylinux


1 Answers

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.

like image 93
Grad van Horck Avatar answered Oct 06 '22 18:10

Grad van Horck