以下功能有效。但我想同时使用“声明”和“喜欢”。如果我用 constraint1 注释掉该行并尝试:
$constraint1 = $query->statement("SELECT * FROM pages WHERE title LIKE '" . $text . "%'");
...查询不起作用。
我收到一个错误:
1: PHP Catchable Fatal Error: 参数 1 传递给 TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory::_or() 必须实现接口 TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface,TYPO3\ 的实例CMS\Extbase\Persistence\Generic\Query 给定,在第 439 行的 [...] 中调用并在 [...]\typo3\sysext\extbase\Classes\Persistence\Generic\Qom\QueryObjectModelFactory.php 第 122 行定义
功能:
/**
* Test
*
* @param string $text
* @return Objects
*/
public function findWordsByText($text) {
$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(FALSE);
$query->getQuerySettings()->setReturnRawQueryResult(TRUE);
$constraint1 = $query->like('title', $text . '%');
// $constraint1 = $query->statement("SELECT * FROM pages WHERE title LIKE '" . $text . "%'");
$constraint2 = $query->like('title', 'new');
$constraint = array($constraint1, $constraint2);
$query->matching(
$query->logicalOr($constraint)
);
$records = $query->execute();
return $records;
}
如果我更改以下行:
$query->matching(
$query->logicalOr($constraint)
);
到 - 逻辑与:
$query->matching(
$query->logicalAnd($constraint)
);
...查询为空。