简体   繁体   English

Drupal 6 中的自定义搜索表单:视图/面板还是自定义 sql?

[英]Custom search form in Drupal 6: Views/Panels or custom sql?

I use CCK in Drupal 6 and I need to build a search form in Drupal with 8-10 fields used as a filter.我在 Drupal 6 中使用 CCK,我需要在 Drupal 中构建一个搜索表单,其中包含 8-10 个字段用作过滤器。 When the user submits the form I need to make a query on the DB applying filters and presenting the result on a table.当用户提交表单时,我需要对应用过滤器的数据库进行查询并将结果显示在表上。
I know how to do this programmatically by building dynamically the SQL-where condition (joining node and content_type_xyz tables) but I would be interested in learning how to do it in the "Drupal way".我知道如何通过动态构建 SQL-where 条件(连接节点和 content_type_xyz 表)以编程方式执行此操作,但我有兴趣学习如何以“Drupal 方式”执行此操作。 I think I would have to use Views and Panels but I don't know if they can be easily implemented in situations like this.我想我将不得不使用视图和面板,但我不知道它们是否可以在这种情况下轻松实现。 I've tried to build some sample views but I think to be faster in creating code by hand.我尝试构建一些示例视图,但我认为手动创建代码会更快。

If you want custom searches you need IMO to do 2 things:如果您想要自定义搜索,您需要 IMO 做两件事:

  1. Hook yourself into _search so you can use Drupal's display for the results.将自己连接到_search,以便您可以使用 Drupal 的显示来显示结果。 Inside this form, you can create your queries for the database or load other content as you wish, just be sure to use pager_query .在此表单中,您可以为数据库创建查询或根据需要加载其他内容,只需确保使用pager_query
  2. Extend the search form that already exists or built your own.扩展已经存在的或构建您自己的搜索表单。 I suggest buliding your own.我建议建立自己的。 use what is already existing from Drupals search form .使用 Drupals 搜索表单中已经存在的内容。 This way, you have a clean way of how to do this.这样,你就有了一个干净的方法来做到这一点。

There is actually no need to use any fancy modules (that doesn't mean you should rule them out, but a search is something so esential that it is quite well handled with the basics).实际上没有必要使用任何花哨的模块(这并不意味着您应该将它们排除在外,但是搜索是非常重要的,它可以很好地处理基础知识)。

Using the above, you'll get a native search form with all it's power and can make use of global paging options.使用上述内容,您将获得一个具有所有功能的本机搜索表单,并且可以使用全局分页选项。

If you do it using views you will only be limited to the filtering you can do using SQL.如果您使用视图执行此操作,您将仅限于使用 SQL 可以执行的过滤。 Views is an SQL builder, and does not contain any 'proper' search functions.视图是一个 SQL 构建器,不包含任何“适当的”搜索功能。 That said, it sounds like Views will do what you want;也就是说,听起来 Views 会做你想做的事; if you create filters under views and then click 'Expose this filter', you will suddenly see fields that allow the user to enter something to filter by appear.如果您在视图下创建过滤器,然后单击“公开此过滤器”,您会突然看到允许用户输入内容以进行过滤的字段出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM