显示knp分页有多少页

Show how many pages in Knp pagination

我在 knp 分页中安装并覆盖了模板。但我需要显示有多少页。例如:第 1 页,共 10 页,第 5 页,共 10 页 e.t.c?我阅读了官方文档,但没有找到答案。

您可以覆盖此模板:https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Resources/views/Pagination/sliding.html.twig

只需使用变量 pageCount 来显示所需的页数。

为此,请在您的 app/Resources/KnpPaginatorBundle/views/Pagination 文件夹中创建一个 sliding.html.twig 文件。

我可以在文档中看到这个抽象分页 class : https://github.com/KnpLabs/knp-components/blob/master/src/Knp/Component/Pager/Pagination/AbstractPagination.php

这个class在第113行有一个方法:

/**
 * Get total item number available
 *
 * @return integer
 */
public function getTotalItemCount()
{
    return $this->totalCount;
}