问题描述
"TYPO3.CMS.Frontend.ContentObject.Exception.ProductionExceptionHandler": Oops,an error occurred! Code: 202008171404455cdd4e46 - {"exception":"TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Exception\\InvalidNumberOfConstraintsException: There must be at least one constraint or a non-empty array of constraints given.
同时,我的存储库中有这段代码
$query->matching($query->logicalAnd($contraints));
我的问题是:如何在TYPO3中编写符合条件的代码:
“至少提供了一个约束或一组非空约束”。
解决方法
首先,在ROOT TS中禁用ExceptionHandler:
config.contentObjectExceptionHandler = 0
正如您的眼神所说:您似乎有一个空数组$ contraints == []。 请发布漏洞代码以获取详细帮助!
示例:
public function findUser(
\VENDOR\Ext1\Domain\Model\MyModel $m
)
{
$query = $this->createQuery();
$constraints = [];
$constraints[] = $query->equals('pid',$m->getPid());
$constraints[] = $query->contains('type',$m->getType());
if ($condition) {
$constraints[] = $query->contains('topics',$m->getTopic());
}
$query->matching(
$query->logicalAnd($constraints)
);
return $query->execute();
}