我想从列值为 的uid所有行中获取列的city值london。我试过这样:$this->getDoctrine()->getRepository(Personal::class)->findOneBy(['city' => 'london']);但后来我只从 1 行得到一个对象。我需要的只是一个看起来像这样的数组:数组(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
2 回答

拉风的咖菲猫
TA贡献1995条经验 获得超2个赞
使用findBy代替findOneBy。它为您提供了实体数组。
但是您无法定义应该获取哪一列。为此,您应该使用 DQL 来定义应该获取的内容。
例如使用查询生成器:
$queryBuilder = $this->createQueryBuilder()
->select('p.uid')
->from(Personal::class, 'p')
->where('p.city = \'london\'');
$uids = $queryBuilder->getQuery()->getResult();
- 2 回答
- 0 关注
- 185 浏览
添加回答
举报
0/150
提交
取消