gpt4 book ai didi

list - 添加一个搜索框来过滤 Symfony 中的结果列表?

转载 作者:行者123 更新时间:2023-12-01 15:32:16 26 4
gpt4 key购买 nike

作为 Symfony 中典型的 indexSuccess 操作的结果,我需要在对象列表中放置一个搜索框。目标很简单:根据条件过滤列表。

我一直在阅读 Zend Lucene approach in Jobeet tutorial ,但这似乎是在用大锤敲螺母(​​至少对于我的要求而言)。

我对自动生成的管理过滤器表单更感兴趣,但我不知道如何在前端实现它。

我可以简单地将搜索框内容传递给操作并构建自定义查询,但有没有更好的方法来做到这一点?

编辑

我忘了说我想要一个通用输入字段而不是每个模型属性的输入字段。

谢谢!

最佳答案

我正在使用这个解决方案,而不是集成 Zend Lucene,我设法使用自动生成的 Symonfy 过滤器。这是我正在做的方式:

//module/actions.class.php
public function executeIndex(sfWebRequest $request)
{
//set the form filter
$this->searchForm = new EmployeeFormFilter();
//bind it empty to fetch all data
$this->searchForm->bind(array());
//fetch all
$this->employees = $this->searchForm->getQuery()->execute();
...
}

我做了一个搜索操作

public function executeSearch(sfWebRequest $request)
{
//create filter
$this->searchForm = new EmployeeFormFilter();
//bind parameter
$fields = $request->getParameter($this->searchForm->getName());
//bind
$this->searchForm->bind($fields);
//set paginator
$this->employees = $this->searchForm->getQuery()->execute();
...
//template
$this->setTemplate("index");
}

将搜索表单转到 mymodule/search 操作很重要。

其实我也在用sfDoctrinePager对于分页设置,直接设置表单生成的查询以获得正确分页的结果。

如果您想在搜索表单中添加更多字段,请检查 this :)

关于list - 添加一个搜索框来过滤 Symfony 中的结果列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5564890/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com