简体   繁体   English

TYPO3 中的高效 Flexform 数据库查询

[英]Efficient Flexform Database Queries in TYPO3

Is there an easy and / or efficient way to make database requests that take fields in flexform columns into account, eg for sorting, where clause, etc.是否有一种简单和/或有效的方法来使数据库请求考虑到 flexform 列中的字段,例如用于排序、where 子句等。

May it be through TypoScript DatabaseQueryProcessor or PHP exec_INSERT/UPDATE/DELETE/SELECTquery.可能是通过 TypoScript DatabaseQueryProcessor 或 PHP exec_INSERT/UPDATE/DELETE/SELECTquery。

I currently don't have a good valid option how to do it, would be really happy for a solution.我目前没有一个很好的有效选择如何做到这一点,我会很高兴有一个解决方案。

UPDATE: Thanks for all of your answers, I was thinking about switching some setups from normal database columns to Flexform to allow backend users to create the form structure dynamically but I obviousely won't do this for fields that I need to search through as this needs to be parsed twice as all of you guys mentioned.更新:感谢您的所有回答,我正在考虑将一些设置从普通数据库列切换到 Flexform,以允许后端用户动态创建表单结构,但我显然不会对需要搜索的字段执行此操作需要像你们提到的那样被解析两次。 Anyways the new FlexForm Processor is pretty cool, it makes reading those fields for normal data output super easy (and it brings an end to different flexform processing of each extension which I was struggling with sometimes).无论如何,新的 FlexForm 处理器非常酷,它使读取这些字段以获取普通数据 output 超级容易(它结束了我有时苦苦挣扎的每个扩展的不同 flexform 处理)。 Thanks for your help.谢谢你的帮助。

No. Flexforms are stored as XML in a text field.不会。Flexform 以 XML 形式存储在文本字段中。 So, for querying entities of the XML, this text field has to be parsed for all rows.因此,对于查询 XML 的实体,必须为所有行解析此文本字段。

What's your use-case?你的用例是什么? Maybe there's another way...或许还有别的办法...

Not really, flexforms are stored as string representation of XML and it will be difficult or impossible to order or search them by some value.并非如此,flexforms 存储为 XML 的字符串表示形式,并且很难或不可能按某个值对它们进行排序或搜索。 The best you can do actually is fetching.实际上,您能做的最好的事情就是获取。 You can try to search by fulltext even with some XML tags, however only thing you can do for sorting is fetching whole set of rows and sorting them in PHP (highly uneffective)即使使用一些 XML 标签,您也可以尝试按全文搜索,但是您可以做的唯一事情是获取整组行并在 PHP 中对它们进行排序(非常无效)

If for some reason sorting by value from FF is really important for you, only option is custom extension, with column storing atomic values.如果出于某种原因从 FF 中按值排序对您来说真的很重要,那么唯一的选择是自定义扩展,列存储原子值。 You can set this order in custom field of form or ie, by hook during save or update of the row.您可以在表单的自定义字段中设置此顺序,或者在保存或更新行期间通过挂钩设置。

You might want to take a look at the ExtractValue approach of MySQL in this case.在这种情况下,您可能想查看 MySQL 的 ExtractValue 方法。

https://dev.mysql.com/doc/refman/5.7/en/xml-functions.html https://dev.mysql.com/doc/refman/5.7/en/xml-functions.html

If you know the exact XPATH to your XML tag, this will return the text value of that XML tag.如果您知道 XML 标签的确切 XPATH,这将返回该 XML 标签的文本值。

SELECT ExtractValue(pi_flexform, '/xpath/to/your/desired/tag') AS flexform_fieldname;

It's not very performant, since still the strings have to be parsed, but in this case it will be done on the MySQL server side with a function that might still give you some advantage over PHP based parsing.它的性能不是很好,因为仍然必须解析字符串,但在这种情况下,它将在 MySQL 服务器端使用 function 完成,这可能仍然比基于 Z2FEC392304A5C23AC138DA228 的解析为您提供一些优势。

We've got some good results with that approach while migrating content elements away from FlexForm fields and into really normalised database fields.在将内容元素从 FlexForm 字段迁移到真正规范化的数据库字段中时,我们使用这种方法获得了一些不错的结果。

In the brand new TYPO3 11.1 there has been implemented a native FlexForm Data Processor into the TYPO3 core:在全新的 TYPO3 11.1 中,在 TYPO3 内核中实现了原生 FlexForm 数据处理器:

10 = TYPO3\CMS\Frontend\DataProcessing\FlexFormProcessor
10 {
    fieldName = my_flexform_field
    as = myOutputVariable
}

See the feature description for more detauls: #89509 - Data Processor to resolve FlexForm data有关更多详细信息,请参阅功能描述: #89509 - 数据处理器来解析 FlexForm 数据

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

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