【问题标题】:How can i make a filter chain in the symfony2如何在 symfony2 中制作过滤器链
【发布时间】:2015-08-01 12:58:29
【问题描述】:

我有一个从 symfony2 迁移 symfony1.4 的项目的工作。有件事让我很困惑。在旧项目中有一些过滤器,我不知道如何用 symfony2 做同样的事情。例如

这是 apps/frontend/config/filters.yml 文件:

    rendering: ~
    security:  ~

    filter1:                 
      class: filter1
    filter2:                 
      class: filter2
    cache:     ~
    execution: ~

还有apps/frontend/lib/filter1.class.php文件:

    class filter1 extends sfFilter
    {
      public function execute($filterChain)
      {
        try{ 
              $filterChain->execute();
        }
        catch(Exception $e)
        {

        }
      }
    }

还有apps/frontend/lib/filter2.class.php文件:

    class filter2 extends sfFilter
    {
      public function execute($filterChain)
      {
           $filterChain->execute();
           //some other execution
      }
    }

我怎样才能用 Symfony2 做同样的事情。任何事情都会不胜感激。 谢谢。

【问题讨论】:

    标签: php symfony filter symfony1 chain


    【解决方案1】:

    我认为这主要取决于你必须在这些过滤器中做什么,但在 Symfony 2 中你应该能够将它们转换为事件监听器;您应该从官方文档中查看framework events 的列表。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-29
      • 2011-04-13
      • 2021-12-31
      • 2019-08-10
      • 2014-10-01
      • 2021-09-09
      • 2021-04-12
      • 1970-01-01
      相关资源
      最近更新 更多