【问题标题】:In Symfony: How to exclude module from filters chain在 Symfony 中:如何从过滤器链中排除模块
【发布时间】:2012-10-11 12:56:20
【问题描述】:

我有一个自定义过滤器做一些事情。

并且我希望特定模块不包含在过滤器链中。换句话说,对于这个模块,我希望我的自定义过滤器不在这个模块上执行,而是在其他模块上执行。

【问题讨论】:

    标签: php symfony1 symfony-1.4 filtering


    【解决方案1】:

    我也使用自定义过滤器,在此过滤器中您可以检索当前模块:

    <?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
      }
    }
    

    否则,您也可以在filters.yml文件中给出排除模块:

    customFilter:
      class: customFilter
      param:
        module_excluded: moduleName
    

    在课堂内:

    <?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
      }
    }
    

    【讨论】:

    • 太棒了,这对我有用,但需要进行一些修改才能使此代码正常工作 ---> 在 filters.yml 中 ---> 它是“param:”而不是“params:”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 2016-03-04
    • 2015-06-13
    相关资源
    最近更新 更多