设置几个小时后,我仍然遇到此错误:
定义“ knp_paginator”不支持配置键“ page_range”
如果我向左移动代码,则会出现此错误:有时无效的yaml,有时找不到knp_paginator 我的文件services.yaml
参数:
locale: 'en'
服务:
_defaults:
autowire: true
autoconfigure: true
public: false
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
knp_paginator:
page_range: 5
default_options:
page_name: page
sort_field_name: sort
sort_direction_name: direction
distinct: true
filter_field_name: filterField
filter_value_name: filterValue
template:
pagination: '@KnpPaginator/Pagination/sliding.html.twig'
sortable: '@KnpPaginator/Pagination/sortable_link.html.twig'
filtration: '@KnpPaginator/Pagination/filtration.html.twig'
和我的文件控制器
/**
* @var $paginator \Knp\Component\Pager\PaginatorInterface
*/
$resultatEleves = $eleveRepository->findAll() ;
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$resultatEleves,
$request->query->getInt('page', 1),
$request->query->getInt('limit', 5)
);
(...) 在第79行之后:
'eleves'=> $pagination,
答案 0 :(得分:0)
首先,您不必将“ knp_paginator”节点放入services.yaml 您可以在config目录中创建knp_paginator.yaml,也可以将其添加到config.yaml中。 同样,您也无法传递findAll结果,您必须将查询传递给分页器。
更多工作示例,您可以在以下位置找到 https://ourcodeworld.com/articles/read/802/how-to-install-the-knppaginatorbundle-to-paginate-doctrine-queries-in-symfony-4