我的存储库类中有以下方法:
$dql = 'SELECT n.name, n.offer_url as url, COUNT(p) as clicks, COUNT(t) as conversions '
. 'FROM AppThanatosBundle:Products n '
. 'LEFT JOIN n.pixels p '
. 'LEFT JOIN p.transactions t '
. 'GROUP BY n.id ';
$query = $this->getEntityManager()
->createQuery($dql);
return $query;
我将它传递给我的控制器中的KnpPaginator Bundle:
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$products,
$request->query->getInt('page', 1),
15
);
如何按列排序:COUNT(p)作为点击次数
在我看来,我尝试使用n.clicks或p.clicks,如:
{{ knp_pagination_sortable(pagination, 'Clicks', 'n.clicks') }}
不幸的是,有一个错误:
There is no such field [clicks] in the given Query component, aliased by [p]