gpt4 book ai didi

doctrine - 在 zf2 Doctrine 2 查询中指定字段

转载 作者:行者123 更新时间:2023-12-04 05:12:02 24 4
gpt4 key购买 nike

我们如何指定要在结果中返回的字段,在使用 Doctrine 2 的 Zend 框架 2 中?
这是我的查询:

$allLanguages = $this->getEntityManager()
->getRepository('Language')
->findAll();

我只想要语言表的结果中的“名称”字段。

最佳答案

我通常像这样使用 DQL 来自定义查询。

    $u = $_GET['u'];
$query = $this->getEntityManager()->createQuery("SELECT u.username FROM Auth\Entity\User u WHERE u.username LIKE :username AND u.companyID = :companyID ");
$query->setParameter('username', '%'.$u.'%')
->setParameter('companyID', $companyID);

$users = $query->getResult();

在你上面的情况下。它可能有点像。
$query = $this->getEntityManager()->createQuery("SELECT l.name FROM Langauge l");

$langaugeNames = $query->getResult();

Doctrine Query Language DQL

Query Builder

关于doctrine - 在 zf2 Doctrine 2 查询中指定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14807857/

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