[英]symfony pagination multiple in same page
I would add several pagination button on the same page. 我会在同一页面上添加几个分页按钮。 Here is my page:
这是我的页面:
Currently I use knppaginator like this: 目前,我像这样使用knppaginator:
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$demandes,
$request->query->getInt('page', 1),
5
);
I try to use knppaginator in this way: 我尝试以这种方式使用knppaginator:
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$demandes,
$request->query->getInt('page', 1),
5
);
$paginator = $this->get('knp_paginator');
$paginationF = $paginator->paginate(
$forumTopics,
$request->query->getInt('page', 1),
5
);
But it does not work. 但这行不通。 When I change page with one it changes the page of the other.
当我用一个更改页面时,它将更改另一个页面。
Thank you. 谢谢。
I think it is because you use same "page" parameter for both paginations. 我认为这是因为您对两种分页使用相同的“页面”参数。 Try this
尝试这个
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$demandes,
$request->query->getInt('page', 1),
5
);
$paginationF = $paginator->paginate(
$forumTopics,
$request->query->getInt('otherPage', 1),
5,
['pageParameterName' => 'otherPage']
);
This is because, per default, all services are shared. 这是因为,默认情况下,所有服务都是共享的。 This means that each time you retrieve the service, you'll get the same instance — see reference .
这意味着,每次检索服务时,您将获得相同的实例- 请参见reference 。
But that can be changed in the definition of your service if you flag it as not shared, as the documentation is proposing it: 但是,如果您将其标记为未共享,则可以在服务的定义中更改它,如文档所建议的那样:
# app/config/services.yml
services:
app.some_not_shared_service:
class: ...
shared: false
# ...
In you case your service is called knp_paginator
and coming from their bundle. 在您的情况下,您的服务称为
knp_paginator
,来自其捆绑包。
So you just have to change your own app/config/services.yml
to make their service non shared: 因此,您只需要更改自己的
app/config/services.yml
即可使其服务不共享:
# app/config/services.yml
services:
knp_paginator:
shared: false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.