自定义操作导致具有多个参数的过滤列表? [英] Custom Action leading to filtered list with multiple parameters?

查看:32
本文介绍了自定义操作导致具有多个参数的过滤列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的自定义操作按钮指向过滤的奏鸣曲列表(课程),但我需要使用两个参数(公司和外部).

I need that my custom action button leads to a filtered Sonata List (Curriculum), but I need to use two parameters (Company and External).

以前,我一直在使用这种方法:Sonata Admin Action Button到预过滤列表,但我无法同时使用两个参数.

Previously, I have been using this approach: Sonata Admin Action Button to Pre Filtered List, but I couldn't manage to use two parameters at the same time.

<a class="btn btn-sm btn-default" href="{{ path('admin_myvendor_mybundle_curriculum_list',{'filter[companies][value]' : object.id }) }}"><i class="fa fa-university"></i> Curriculums </a>

知道如何解决这个问题吗?我想过创建一个控制器并使用自定义的 QueryBuilder,但我仍然想使用 Sonata 列表(并且不覆盖我在 Admin 中的默认 ListMapper)

Any idea how to solve this? I thought about creating a controller and using a custom QueryBuilder but I still want to use Sonata list (and without overwriting my default ListMapper in Admin)

推荐答案

您需要做的是覆盖管理员中的 createQuery() 方法.

What you will need to do to achieve this is override the createQuery() method in your admin.

棘手的部分是列表的原始查询使用 SELECT DISTINCT,因此对于您将添加到查询的每个订单,您需要将相同的字段添加到选择语句中.

the tricky part is that the original query for the list uses SELECT DISTINCT so for each order by that you will add to the query you will need to add the same field to the select statement.

https://github.com/sonata-project/SonataAdminBundle/issues/1548

在我的一个包中,我使用了一种解决方法,通过扩展 ProxyQuery 类,自动按 by 子句将字段添加到查询的选择部分.

In one of my bundles i used a workaround to automatically add fields in order by clauses to the select part of the query by extending the ProxyQuery class.

如果你想看看:https://github.com/blast-project/DoctrinePgsqlBundle/blob/master/Datagrid/ProxyQuery.php 魔法发生在第 98 行和第 112 行之间

if you want to have a look: https://github.com/blast-project/DoctrinePgsqlBundle/blob/master/Datagrid/ProxyQuery.php the magic happens between line 98 and line 112

这篇关于自定义操作导致具有多个参数的过滤列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆