【问题标题】:TYPO3 extbase equals does not workTYPO3 extbase equals 不起作用
【发布时间】:2017-03-17 03:23:53
【问题描述】:

我只需要获取type = 0的记录,但查询后,我得到了所有类型的所有记录

  public function findPeople() {
        $query = $this->peopleRepository->createQuery();
        $query->equals('type', 0);
        $query->setOrderings(
            array(
                'uid' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
            )
        );
        return $query->execute();
    }


    /**
     * action people
     *
     * @return void
     */
    public function listAction()
    {
        $people = $this->findPeople();
        $this->view->assign('people', $people);
    }

【问题讨论】:

  • 旁注:findPeople 方法应该在 PeopleRepository 类中,而不是在控制器类中...

标签: typo3 extbase


【解决方案1】:

需要在repository方法中添加matching()方法:

  public function findPeople() {
    $query = $this->peopleRepository->createQuery();
    $query->matching($query->equals('type', 0));
    $query->setOrderings(
        array(
            'uid' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
        )
    );
    return $query->execute();
}

见:https://docs.typo3.org/typo3cms/ExtbaseFluidBook/6-Persistence/3-implement-individual-database-queries.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多