【发布时间】:2017-08-02 16:35:56
【问题描述】:
什么是 DQL findBy() 查询语法?
像这样: $this->getDoctrine()->getRepository("AppBundle:Users")->findBy($queryWhere);
【问题讨论】:
什么是 DQL findBy() 查询语法?
像这样: $this->getDoctrine()->getRepository("AppBundle:Users")->findBy($queryWhere);
【问题讨论】:
它将为 WHERE CLAUSE 创建标准
$repository->findBy(['email' => 'test@test.com', 'city' => 'Berlin'])
SELECT * FROM table WHERE email = "test@test.com" AND city = "Berlin"
有兴趣的可以看看下面链接下的方法getSelectSQL
【讨论】:
这通常与实体的属性一起使用。它需要一个数组,其中键作为实体上的属性名称,值作为您正在搜索的内容。
例子:
$this->getDoctrine()
->getRepository('AppBundle:Users')
->findBy(['id' => $id])
;
$this->getDoctrine()
->getRepository('AppBundle:Users')
->findBy(['userName' => $userName])
;
$this->getDoctrine()
->getRepository('AppBundle:Users')
->findBy(['email' => $email])
;
您可以在此处阅读更多信息:https://symfony.com/doc/current/doctrine.html#fetching-objects-from-the-database
【讨论】:
select u from ...这样的dql语法是什么