什么是DQL findBy()查询语法?
像这样:$this->getDoctrine()->getRepository("AppBundle:Users")->findBy($queryWhere);
发布于 2017-08-03 04:33:25
它将为WHERE子句创建条件
$repository->findBy(['email' => 'test@test.com', 'city' => 'Berlin'])
SELECT * FROM table WHERE email = "test@test.com" AND city = "Berlin"如果您感兴趣,可以查看以下链接下的方法getSelectSQL
http://www.doctrine-project.org/api/orm/2.5/source-class-Doctrine.ORM.Persisters.Entity.BasicEntityPersister.html#877-891
发布于 2017-08-03 00:49:19
这通常与实体的属性一起使用。它接受一个数组,其中key作为实体的属性名称,value作为您要搜索的内容。
示例:
$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
https://stackoverflow.com/questions/45466399
复制相似问题