PHP 中的通用声明式表达式生成器

发布于 2024-07-23 20:58:21 字数 495 浏览 8 评论 0 原文

各位,

我正在寻找构建一个 PHP5 UI,我非常确定它对于许多应用程序来说是常见的。 基本上,它是一个表达式生成器,允许用户指定通过逻辑运算符 (AND/OR) 组合的表达式,如下所示:

  • FieldX > 3 AND FieldY = 5
  • FieldY = "bob" 并且 FieldZ 不为空
  • FieldX > '5/23/2007' OR (FieldY = 5 AND FieldY is not null)

理想情况下,这样的系统将允许我作为程序员指定用户可以选择的参数列表(列)以及每个参数的数据类型。 它还会提供一个很好的、用户友好的界面来定义这样的表达式 - 我想象像一个表,其中每行都有几个选择器:

[列] [条件] [值] [和/或] [列] [条件] [值] [AND/OR] ...

您知道有一个开源组件可以做类似的事情吗? 或者也许是此类功能的一部分?

Folks,

I'm looking to build a piece of PHP5 UI that I'm pretty sure is common to a bunch of applications. Basically, it's an expression builder that allows users to specify expressions combined through logical operators (AND/OR), like this:

  • FieldX > 3 AND FieldY = 5
  • FieldY = "bob" and FieldZ is not null
  • FieldX > '5/23/2007' OR (FieldY = 5 AND FieldY is not null)

Ideally, a system like that would allow me as a programmer to specify the list of parameters that the user can pick (columns) and the data type for each. It would also provide a nice, user-friendly interface for defining expressions like that - I'm imagining something like a table, where each row has several pickers:

[Column] [Condition] [Value] [AND/OR]
[Column] [Condition] [Value] [AND/OR]
...

Do you know of an open-source component that does something like that? Or maybe a part of this kind of functionality?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

不必你懂 2024-07-30 20:58:21

一句警告。 这些类型的通用表达式生成器通常被认为是解决各种用户问题的优秀解决方案。 这种想法往往是这样的:

  • 用户想要所有这些不同的报告
  • 我们无法为他们提供 SQL 访问权限(即使他们能够理解)
  • 我们没有时间编写所有这些自定义报告
  • 因此,我'将为他们提供一种简单的方法来编写查询,而无需了解特定的语法、表和字段。

这不一定是一个坏主意,但我们在我的公司发现,非技术用户在理解和构建比一组 ANDS 或一组 ORS 更复杂的表达式时遇到了惊人的困难。 这对于我们程序员来说很难理解,因为我们大多数人甚至在学习编程之前就可能对布尔逻辑有直观的理解。

我建议您不要尝试给予他们完全的灵活性来创建他们想要的任何表达式,而是组合一个 UI,让程序员在后端定义更复杂的东西,但在前端为用户提供简单的选择 -结尾。 显然,这说起来容易做起来难。

请记住,有时最终用户面临的困难并不是他们不知道表达想法的正确语法。更常见的是,他们甚至不知道如何以明确的方式表达他们的想法,即使他们获得了一种简单的方法来做到这一点。

注意:我并不是说最终用户总是白痴 - 只是他们的想法可能与我们疯狂的开发人员不同。

A word of caution. These types of generic expression builders are commonly thought of as excellent solutions to a variety of user problems. The thinking tends to go along these lines:

  • The user wants all these different reports
  • There's no way we're giving them SQL access (even if they could understand it)
  • We don't have time to write all these custom reports
  • Therefore, I'll make an easy way for them to write queries without having to know specific syntax, tables and fields.

This is not necessarily a bad idea, but what we have found at my company is that non-techie users have surprising difficulty understanding and building expressions more complex than a group of ANDS or a group of ORS. This is hard for us programmers to grasp, as most of us probably had an intuitive understanding of boolean logic even before we learned to program.

I would recommend that you not try to give them complete flexibility to create whatever expression they want, and instead you put together a UI that lets you the programmer define something more complicated on the back-end but gives the user simple choices on the front-end. This is easier said than done, obviously.

Remember - sometimes the difficulty for end users isn't the fact that they don't know the right syntax to express their idea in. More often it's because they don't even know how to formulate their thoughts in an unambiguous way, even if they were provided an easy way to do so.

NOTE: I'm not saying the end users are always morons - just that their minds may work differently from us crazy developers.

別甾虛僞 2024-07-30 20:58:21

这不完全是一个组件,但您可以查看 Magento 中的购物车规则生成器,用于此类功能的可靠 PHP 实现。 它是针对电子商务定制的,因此它不是通用的数据库覆盖层,但它确实有一个很棒的条件生成器界面。

This isn't exactly a component, but you might take a look at the Conditions tab of the Shopping Cart rule builder in Magento for a solid PHP implementation of this type of functionality. It is customized towards e-commerce, so it is not a generic database overlay, but it does have a great condition builder interface.

绅士风度i 2024-07-30 20:58:21

我认为这是一个非常有趣的想法。 您打算将这个项目用于个人用途还是通过工作?

如果您打算亲自处理这个项目,也许您应该自己编写它并将其变成一个开源项目。 看来大家已经对这个领域产生了一些兴趣,这将是一次很好的学习经历。

否则,我可以看到一家公司如何在这样的事情中找到价值。 它将为程序员提供另一个实用工具,可以帮助他们更轻松地完成工作,并从长远来看带来回报。

不管怎样,这个项目是赢了。 你会学到很多东西,并创造出其他人认为有用的东西。

I think this is a very interesting idea. Are you planning on working on this project for personal use or through work?

If you are planning on working on this project personally, maybe you should write it yourself and turn it into an open source project. It looks like there is already some interest in this area and it would be a good learning experience.

Otherwise, I can see how a company could find value in something like this. It would give the programmers another utility that could help them do their job a little bit easier and pay dividends in the long run.

Either way, this project is win. You will learn alot, and create something that other people find useful.

花开雨落又逢春i 2024-07-30 20:58:21

看看这个: http://www.codeproject.com/KB/custom- controls/SqlWhereBuilder.aspx

下载该组件的客户端 JavaScript 库版本并根据您的需要对其进行自定义。 干杯。

Check this out: http://www.codeproject.com/KB/custom-controls/SqlWhereBuilder.aspx

Download the client side JavaScript Library version of the component and customize it to your needs. Cheers.

你是我的挚爱i 2024-07-30 20:58:21

我首先创建一个面向对象的查询模型。 例如。 条件对象。 下一步是编写一个允许操作该模型结构的 UI。

I'd start by creating an object oriented query model. Eg. Criteria-objects. The next step is then to write a UI which allows manipulation of this model structure.

再浓的妆也掩不了殇 2024-07-30 20:58:21

我最近自己完成了这样的功能,恕我直言,编写自己的实现更容易。

I've recently done such functionality by myself and, IMHO, it's easier to write your own implementation.

舟遥客 2024-07-30 20:58:21

我认为这与 UI 的关系比 PHP 的关系更大。 你最好重新标记你的问题。 也许您只想在 PHP 中解析这些定义,在这种情况下我建议使用 preg_replace_callback。

I think this is more related to UI than PHP in general. You'd better retag your question. Maybe you just want to parse these definitions in PHP, in this case I'd suggest using preg_replace_callback.

氛圍 2024-07-30 20:58:21

为什么不尝试使用 smarty 这是一个模板引擎。 您只需要获取并解析用户输入。

现在我在想,以任何方式执行此操作都需要检查用户输入以避免注入。

why dont try using smarty which is a template engine that. you just need to get and parse the user input.

Now that I'm thinking, do this in any way will need you checking the user input to avoid injections.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文