How to Add Non-page Arguments in the KnpPaginatorBundle

Asked 1 years ago, Updated 1 years ago, 88 views

I'd like to use KnpPaginatorBundle for paging in symfony2.
I don't know how to describe the search criteria if you want to include them in paging in the list of search results.

/blog/February 2016


with the action accessed at the URL:
if 2016 is acquired under the name year and 02 is acquired under the name month. I would like to add the query year=2016&month=02 to the second page.
How do I describe it?

$paginator=$this->get('knp_paginator');
$posts=$paginator->paginate($query,$page,3);

I think I will add it here somehow.
I couldn't find a way to write it.

Thank you for your cooperation.

symfony2

2022-09-29 22:34

1 Answers

I'll write it down because I solved it myself.
Apparently, Knp_paginator does not have the ability to pass parameters to itself.
Implement the following actions:

$param=array('year'=>$year,'month'=>$month);
$paginator = $this->get('knp_paginator');
$pagination=$paginator->paginate($query,$page,3);
return$this->render('Notice/index.html.twig', array('pagination'=>$pagination,'param'=>$param));

The template contains

{%if pagination.totalItemCount>0%}
{% include "Common/pager.twig" with {'pages':pagination.paginationData, 'param':param, 'route'=>'notice_index'}%}
{% endif%}

The contents of pager.twig are

{%if pages.previous is defined%}
<li><a href="{ path(routes, param | merge({'page':pages.previous}))}}"aria-label="Previous"><spanaria-hidden="true">forward</span>>>
{% endif%}

{% for page in pages.pagesInRange%}
<li {%if page==pages.current%} class="active"{%endif%}><a href="{{path(routes,param|merge({'page':page}))}">>span>{{page}}}<</span>>>>>>
{% endfor%}

{% if pages.next is defined%}
<li><a href="{{path(routes, param|merge({'page':pages.next}))}}"aria-label="Next"><spanaria-hidden="true">Next;/span>>>a>>>
{% endif%}

This is how it worked.


2022-09-29 22:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.