0

Is there an example to see how one can implement a search form using Zend Forms in Zend Framework2. I needed a search form for every category and every category has different columns in the database which needs to be searched.

Let me say I have a Country category, under this there are many elements which can be searched like country name, states belonging to the county, language spoken in the country and so on.

So when a user types either a state or country or language I need to display all possible details. Is there something like a module already existing in Zend Framework2 or I should be implementing everything form scratch. In case if I need to do all from scratch, then what is the best way to approach this.

Im using Doctrine ORM to communicate with my DB. So in case if somebody has already worked on both of these then your suggestions would be appreciated.

4

1 回答 1

0

您想通过您的学说实体中定义的属性来构建您的 zend_form 吗?你不得不

  • 使用反射来获取所有属性 + 数据类型 + is-nullable?,
  • 遍历属性(最终实现一种安全机制来整理不需要的列),
  • 迭代时构建zend_form,创建对应的zend_form_elements

之后,您必须根据从表单中获得的数据创建 Doctrine 查询,为您通过 POST 获得的每个属性动态设置 WHERE 语句。

但这不是很实用。

在你的情况下,我会建立一个全文搜索引擎,如 lucene、elastic search 或 solr。

我不知道 ZF2(它是否已经处于可用于生产环境的状态?-当我们在一年前分析它时,我们决定不使用它),但 ZF1 有一个 zend_search 类,它允许轻松连接到solr 衍生。

我们不使用它虽然导致它很慢。也许现在 ZF2 中有更好的实现..

于 2012-12-12T22:40:26.307 回答