gpt4 book ai didi

php - Doctrine findBy where and order

转载 作者:行者123 更新时间:2023-12-03 22:57:53 26 4
gpt4 key购买 nike

我有一个关于 symfony Doctrine 的片段,它按降序选择数据。尝试应用 where 子句某些字段等于 true 是一个问题。下面是我的片段

$results = $this->getDoctrine()->getRepository('RealBundle:Foo')->findBy([], ['id' => 'DESC','active' => true]); 

我有一个名为 active 的字段。检索 active 等于 true 的所有结果是一项挑战

以上尝试报错

Invalid order by orientation specified for RealBundle\Entity\Foo#active

最佳答案

第一个参数是 WHERE 子句,第二个参数是 ORDER。

$results = $this
->getDoctrine()
->getRepository('RealBundle:Foo')
->findBy(['active'=>true], ['id' => 'DESC']);
findBy签名如 the documentation 中所述
findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)

关于php - Doctrine findBy where and order,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48265488/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com