简体   繁体   English

在TYPO3 Extbase查询中使用Concat

[英]Using Concat in TYPO3 Extbase Query

i am struggling a little challenge and i am wondering what the solution might be as I couldn't find an answer in the documentation. 我正在努力应对一个小挑战,我想知道解决方案是什么,因为我在文档中找不到答案。

Here is my current working query (part): 这是我当前的工作查询(部分):

$constraints[] = $query->like('kategorie', '%'.$kategorie.'%');

What I want to do is something like: 我想做的是这样的:

$constraints[] = $query->like(CONCAT(',', kategorie, ','), '%,'.$kategorie.',%');

Which obviously doesn't work at all. 这显然根本不起作用。 : -) :-)

Every Help is really appriciated. 每个帮助都非常有用。 Hope someone know the right syntax. 希望有人知道正确的语法。 TYPO3 Version is latest 6.1 TYPO3版本是最新的6.1

Thank's alot! 非常感谢!

First of all, Extbase query generation didn't change in 6.0, so it's the same for 4.x and 6.x. 首先,Extbase查询生成在6.0中没有更改,因此对于4.x和6.x来说是相同的。

Maybe you misunderstand the way Extbase is builing the query. 也许您误解了Extbase构建查询的方式。

$query->like('property', '%value%');

will return an object when %value% is contained in "property". 当“属性”中包含%value%时,将返回一个对象。 Such a property must be defined in the domain model. 这种属性必须在域模型中定义。 You can only query properties that have a "getProperty" method in their domain model. 您只能查询在其域模型中具有“ getProperty”方法的属性。

Looking at your code, I think you're finding a way to query for a value being present in a comma-separated value list? 查看您的代码,我认为您正在寻找一种查询以逗号分隔的值列表中存在的值的方法? Then you would use 那你会用

$query->in('kategorien', $kategorie);

EDIT: 编辑:

Your specific problem seems to be that you are not using a true relation for assigning "Kategorien" to your entity. 您的特定问题似乎是您没有使用真正的关系将“ Kategorien”分配给您的实体。 You're using a comma-separated list to hold references to another model. 您正在使用逗号分隔的列表来保存对另一个模型的引用。 You're discouraged to do so, but it is technically possible and used in the TYPO3 core: The FrontendUser model has a property "usergroup" that works in the same way. 不建议您这样做,但是从技术上讲,它是可能的,并已在TYPO3内核中使用:FrontendUser模型具有一个属性“ usergroup”,其工作方式相同。

Please have a look at the FrontendUser model: https://git.typo3.org/Packages/TYPO3.CMS.git/blob/HEAD:/typo3/sysext/extbase/Classes/Domain/Model/FrontendUser.php 请看一下FrontendUser模型: https ://git.typo3.org/Packages/TYPO3.CMS.git/blob/HEAD: /typo3/sysext/extbase/Classes/Domain/Model/FrontendUser.php

The annotation of your Kategorien must be correct, eg: 您的Kategorien注释必须正确,例如:

/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\My\Extension\Domain\Model\Kategorien>
*/
protected $kategorien;

Also make sure that getKategorien is correct. 还要确保getKategorien是正确的。

If you still have problems, keep in mind that the TCA definition must be working to have Extbase work correctly. 如果仍然有问题,请记住,TCA定义必须起作用才能使Extbase正常工作。

In my opinion, a best practise would be to use the category API introduced in TYPO3 6.0: http://wiki.typo3.org/TYPO3_6.0#Category 我认为,最佳做法是使用TYPO3 6.0中引入的类别API: http : //wiki.typo3.org/TYPO3_6.0#Category

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

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