[英]Override KNP Paginator entity
I am currently working with KNP Paginator to paginate results. 我目前正在与KNP Paginator合作分页结果。 I get serialize paginator object and get response in following form:
我得到序列化paginator对象并获得以下形式的响应:
"current_page_number": 1
"num_items_per_page": 5
"items": [5]
"total_count": 35
"paginator_options": {
"pageParameterName": "page"
"sortFieldParameterName": "sort"
"sortDirectionParameterName": "direction"
"filterFieldParameterName": "filterField"
"filterValueParameterName": "filterValue"
"distinct": true
}-
"custom_parameters": [0]
"route": "api_tags_list"
"params": [0]
"page_range": 5
"template": "KnpPaginatorBundle:Pagination:sliding.html.twig"
"sortable_template":
"KnpPaginatorBundle:Pagination:sortable_link.html.twig"
"filtration_template":
"KnpPaginatorBundle:Pagination:filtration.html.twig"
Is it possible to override KNP paginator entity so that response will not include templates
but included total number of pages
? 是否可以覆盖KNP paginator实体,以便响应不包含
templates
但包含total number of pages
?
Desired output: 期望的输出:
"current_page_number": 1
"num_items_per_page": 5
"items": [5]
"total_count": 35
"paginator_options": {
"pageParameterName": "page"
"sortFieldParameterName": "sort"
"sortDirectionParameterName": "direction"
"filterFieldParameterName": "filterField"
"filterValueParameterName": "filterValue"
"distinct": true
}-
"custom_parameters": [0]
"route": "api_tags_list"
"params": [0]
"page_range": 5
"total_page_number": 7
You could proceed in two way: 你可以用两种方式进行:
1) Define the serialization of the KNP paginator defining what you want to display as described here (you could also define the prev/next route with a jms subscriber or with banzigahatoas bundle). 1)定义KNP分页程序的序列化定义你想要的描述显示的内容在这里 (你也可以定义与JMS用户或banzigahatoas束的上/下一个路径)。 The result in the controller will be:
控制器中的结果将是:
$paginator = $this->get('knp_paginator');
$data =
$paginator->paginate(
$query, /* query NOT result */
2 /*page number*/,
2/*limit per page*/
);
return $data;
2) Or managed by hand the result in this manner: 2)或以这种方式手工管理结果:
$paginator = $this->get('knp_paginator');
$data =
$paginator->paginate(
$query, /* query NOT result */
2 /*page number*/,
2/*limit per page*/
);
return [
'items' => $data->getItems(),
'pagination' => $this->paginationToArray($data)
];
Where paginatorToArray method is something like this . paginatorToArray方法就是这样的 。
Hope this help 希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.