TYPO3 Extbase - 仅查询特定uid范围内的记录

时间:2017-03-03 19:26:09

标签: typo3 extbase typo3-7.6.x

如何仅渲染特定uid范围内的记录?让我们说我只想渲染它所在的记录。高于100且低于200

/**
 * action list
 *
 * @return void
 */
public function listAction() {

$this->view->assign('records', $this->testRepository->findAll());

}

我是否需要使用MathUtility并且它是​​isIntegerInRange ...但是如何?

1 个答案:

答案 0 :(得分:4)

在存储库中使用您自己的功能。

控制器

/**
 * action list
 *
 * @param integer $minUid
 * @param integer $maxUid
 * @return void
 */
public function listAction() {

    $this->view->assign('records', $this->testRepository->findUidRange($minUid,$maxUid));

}

存储库

/**
 * Find records filtered by uid from to
 *
 * @param integer $minUid
 * @param integer $maxUid
 * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result
 */
public function findUidRange($minUid = NULL, $maxUid = NULL) {
    $query = $this->createQuery();
    return $query->matching(
            $query->logicalAnd(
                    $query->greaterThan('uid', $minUid),
                    $query->lessThan('uid', $maxUid),
                    $query->equals('deleted', 0)
            ))->execute();
}