Sonata Admin configureListFields [英] Sonata Admin configureListFields
本文介绍了Sonata Admin configureListFields的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 configureListFields 中的 Sonataadmin 中进行自定义查询?.
is it possible to make a custom query in sonataadmin in configureListFields ? .
在这个函数中:
受保护的函数 configureListFields(ListMapper $listMapper){$listMapper->>添加(....;}
谢谢!
推荐答案
你应该像这样覆盖 createQuery
方法 (来源):
You should override createQuery
method like this (source):
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
// this is the queryproxy, you can call anything you could call on the doctrine orm QueryBuilder
$query->andWhere(
$query->expr()->eq($query->getRootAlias().'.username', ':username')
);
$query->setParameter('username', 'test'); // eg get from security context
return $query;
}
AFAIK,您不能更改查询的 SELECT
部分,也不能使用 GROUP BY
,因为 Sonata 在内部至少运行此查询两次.首先,它检查查询返回了多少行.其次,它运行这个查询分页.
AFAIK, you cannot change SELECT
part of the query and you cannot use GROUP BY
, because internally Sonata runs this query at least two times. First, it checks how many rows query returns. Second, it runs this query paginated.
这篇关于Sonata Admin configureListFields的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文