Search code examples
phpsymfony1symfony-1.4filtering

In Symfony: How to exclude module from filters chain


I have a custom filter do some stuff.

And I want specific module to be not included in the filter chain. In another word, for this module I want my custom filter not execute on this module and executing for other modules.


Solution

  • I use custom filter too and inside this filter you can retrieve the current module:

    <?php
    
    class customFilter extends sfFilter
    {
      public function execute ($filterChain)
      {
        $context = $this->getContext();
    
        if ('moduleName' == $context->getModuleName())
        {
          // jump to the next filter
          return $filterChain->execute();
        }
    
        // other stuff
      }
    }
    

    Otherwise, you can also give the excluded module inside the filters.yml file:

    customFilter:
      class: customFilter
      param:
        module_excluded: moduleName
    

    And inside the class:

    <?php
    
    class customFilter extends sfFilter
    {
      public function execute ($filterChain)
      {
        $context = $this->getContext();
    
        if ($this->getParameter('module_excluded') == $context->getModuleName())
        {
          // jump to the next filter
          return $filterChain->execute();
        }
    
        // other stuff
      }
    }