0

Symfony 4 和 KnpPaginatorBundle。我有一个相同型号的库存表很多次。我想在我的存储库中做这样的事情:

$query = $this->createQueryBuilder(...);
$query = $query->andWhere(.....);
$query = $query->addGroupBy(brand, model);
$query = $query->addOrderBy(brand, model);
return $query;
......
KnpPaginatorBundle

我希望我拥有的骨架

在 KnpPaginatorBundle 处理后我想返回多个字段的问题..(我认为 id 有问题)


有点像:(它按我的意愿工作)

        $conn = $this->getEntityManager()->getConnection();
        $sql = 'SELECT objet,marque,type FROM stock GROUP BY objet,`type`,marque ORDER BY marque,type';
        $stmt = $conn->prepare($sql);
        $stmt->execute();
        return $stmt->fetchAllAssociative():

但我想使用上面的编码..

抱歉我的英语很接近;-)

4

1 回答 1

0

感谢您的关注!这是我对我的问题的回答:

$query = $this->createQueryBuilder('a');
$query->select('a.objet,a.marque,a.type');
$query->addGroupBy('a.objet');
$query->addGroupBy('a.marque');
$query->addGroupBy('a.type');
$query->addOrderBy('a.marque');
$query->addOrderBy('a.type');
dd($query->getQuery()->execute());
于 2021-01-05T21:42:22.030 回答