简体   繁体   English

如何将参数附加到 KNP 分页器 url

[英]How To append parameters to KNP paginator url

I am using the KNP Paginator bundle for pagination.我正在使用 KNP Paginator 包进行分页。 Does anyone know how to append parameters to the generated url?有谁知道如何将参数附加到生成的 url 中?

Here is my set up:这是我的设置:

 {{ knp_pagination_sortable(supplierProducts, 'Product Sku', 'p.name') }}

I want to add &section=supplier to the end of the URL, I just have no clue how to do it.我想将 &section=supplier 添加到 URL 的末尾,我只是不知道该怎么做。 I looked through the docs but did not find any info.我浏览了文档,但没有找到任何信息。

Please help if you can.如果可以的话请帮忙。

Thanks.谢谢。

According to the KnpPaginator documentation , you can append query parameters as follows:根据KnpPaginator 文档,您可以按如下方式附加查询参数:

$paginator = $this->get('knp_paginator');
...
$pagination->setParam('section', 'supplier');

You could extend the kn_pagination_sortable template.您可以扩展 kn_pagination_sortable 模板。 When you run "knp_pagination_sortable" behind the scenes, it will basically generate an HTML according to your specifications.当您在后台运行“knp_pagination_sortable”时,它基本上会根据您的规范生成 HTML。 However, you can extend that.但是,您可以扩展它。 Instead of using the bundle's generated HTML for that element, you can write your own template for that pagination_sortable.您可以为该 pagination_sortable 编写自己的模板,而不是为该元素使用包生成的 HTML。 This is a snippet from the project I'm working on.这是我正在从事的项目的一个片段。 This is at my pagination_sortable.html.twig:这是在我的 pagination_sortable.html.twig:

<a id="table_sorteable_{{ options['title']|lower }}" {% for attr, value in options %} {{     attr }}="{{ value }}"{% endfor %}>
    {{ title }}
    <b class="caret {{ options['class'] }}"></b>
</a>

Get it?得到它? You can have a template like that and change it according to your needs.您可以拥有这样的模板并根据您的需要进行更改。

You can find more information on the link below.您可以在下面的链接中找到更多信息。

Overriding default pagination template 覆盖默认分页模板

As of 2020, and KnpPaginatorBundle v5.3, the solution proposed by @likeitlikeit doesn't work because the setParam method doesn't exist any more.截至 2020 年和 KnpPaginatorBundle v5.3,@likeitlikeit 提出的解决方案不起作用,因为setParam方法不再存在。

But you can append parameters to the sort and pagination links directly in the knp helpers in twig:但是您可以直接在 twig 的 knp 帮助器中将参数附加到排序和分页链接:

{# 4th parameter for sortable helper #}
{{ knp_pagination_sortable(results, column.title, column.alias, {}, params) }}

{# 3rd parameter for pagination helper #}
{{ knp_pagination_render(results, '', params) }}

For example, if you want to include the query parameters in the sort and pagination links, you can do:例如,如果要在排序和分页链接中包含查询参数,可以执行以下操作:

{# Sort - pass all query parameters except sort column and direction #}
{% set params=app.request.query.all | filter((v, k) => (k != 'direction' and k != 'sort'))%}
{% for column in ... %}
    {{ knp_pagination_sortable(results, column.title, column.alias, {}, params) }}
{% endfor %}

{# Pagination #}
{{ knp_pagination_render(results, '', app.request.query.all) }}

要在 url 中添加参数,我是这样进行的:在前面:

 {{ knp_pagination_render(clients, ('annuaire/my_pagination.html.twig'), {"type": type ? type : '' ,"city": city ? city : ''}) }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM