简体   繁体   English

TYPO3 数据库查询

[英]TYPO3 Database Queries

I have a problem in my extension that I work with.我使用的扩展程序有问题。 I got this error:我收到了这个错误:

"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.

and at the same time, I have this code in my repository同时,我的存储库中有这段代码

$query->matching($query->logicalAnd($contraints));

my question is: how can I write the code in TYPO3 which matches with the condition:我的问题是:如何在符合条件的 TYPO3 中编写代码:

"at least one constraint or a non-empty array of constraints given". “给定至少一个约束或一组非空约束”。

First of all, disable ExceptionHandler in ROOT TS:首先,在 ROOT TS 中禁用 ExceptionHandler:

config.contentObjectExceptionHandler = 0 

As your eyception said: it seems you have had an empty array $contraints == [].正如您所说的:您似乎有一个空数组 $contraints == []。 Please publish the hole code for detailed help!详细帮助请发布孔代码!

Example:例子:

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();

}

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

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