【问题标题】:Symfony : How to filter data on the frontend like in the backendSymfony:如何像在后端一样过滤前端的数据
【发布时间】:2011-04-15 11:53:52
【问题描述】:

在 symfony 1.4 / Doctrine 的后端,您有一个工具可以让您根据日期、位置、年龄(以及更多根据您的模型)过滤数据

我正在寻找一种方法来做同样的事情(通过一些自定义,例如删除一些字段),但在 前端。我没有找到任何有关如何操作的文档

你有什么想法吗?

【问题讨论】:

    标签: php symfony1 filtering frontend


    【解决方案1】:

    如果你想完全像在后端那样做,你可以在前端应用程序上使用管理生成器。更通用和可定制的方法是简单地创建列表和过滤器操作并使用 Symfony 的表单过滤器。下面是模型类“Article”的一个基本示例:

    在动作类中:

    class articleActions extends sfActions
    {
      public function executeList(sfWebRequest $request)
      {
        $this->form = new ArticleFormFilter();
        $this->pager = new sfDoctrinePager('Article');
      }
    
      public function executeFilter(sfWebRequest $request)
      {
        $this->form = new ArticleFormFilter();
        $this->form->bind($request[$this->form->getName()]);
        if ($this->form->isValid())
        {
          $this->pager = new sfDoctrinePager('Article');
          $this->pager->setQuery($this->form->getQuery());
          $this->setTemplate('list');
        }
        //handle invalid form here
      }
    }
    

    在视图中,像这样迭代 throw pager:

     foreach($pager->getResults() as $article)
    

    Doctrine FormFilter 与 Doctrine 表单非常相似。通过在 FormFilter::configure() 中配置表单开始;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-15
      • 2017-09-07
      • 2012-01-23
      • 1970-01-01
      • 2012-10-23
      • 2014-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多