在Symfony中:如何从过滤器链中排除模块

5 php symfony1 filtering symfony-1.4

我有一个自定义过滤器做一些东西.

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

j0k*_*j0k 3

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

<?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
  }
}
Run Code Online (Sandbox Code Playgroud)

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

customFilter:
  class: customFilter
  param:
    module_excluded: moduleName
Run Code Online (Sandbox Code Playgroud)

在班级内部:

<?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
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 太好了,这对我有用,但是需要进行一些修改才能使此代码工作 ---&gt; 在filters.yml 中 ---&gt; 它是“param:”而不是“params:” (2认同)