扫码关注官方订阅号
嗨,
我请求帮助创建索引的分页。我尝试了很多方法,但每个人都失败了。 下面我附上该项目的数据:
查看 MySql 和 symfony 组件
实现分页器的控制器
我必须更改什么才能使其正常工作?
代码KnpPaginator
错误
我在我的旧项目中有这个分页实现,看看也许你可以找到适合你的东西。
/** * @param EntityManagerInterface $entityManager * @param PaginatorService $paginatorService * @param Request $request * @return Response */ #[Route('/service', name: 'service_index')] public function index( EntityManagerInterface $entityManager, PaginatorService $paginatorService, Request $request ): Response { return $this->render('service/index.html.twig', [ 'services' => $paginatorService->paginate($entityManager->getRepository(Service::class)->findAll(), $request) ]); } class PaginatorService { public function __construct( private PaginatorInterface $paginator, ) { } public function paginate($query, Request $request) { return $this->paginator->paginate( $query, $request->query->getInt('page', 1), 15 ); } } {{ knp_pagination_render(services, '/pagination/bootstrap_v5_pagination.html.twig') }}
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
我在我的旧项目中有这个分页实现,看看也许你可以找到适合你的东西。
/** * @param EntityManagerInterface $entityManager * @param PaginatorService $paginatorService * @param Request $request * @return Response */ #[Route('/service', name: 'service_index')] public function index( EntityManagerInterface $entityManager, PaginatorService $paginatorService, Request $request ): Response { return $this->render('service/index.html.twig', [ 'services' => $paginatorService->paginate($entityManager->getRepository(Service::class)->findAll(), $request) ]); } class PaginatorService { public function __construct( private PaginatorInterface $paginator, ) { } public function paginate($query, Request $request) { return $this->paginator->paginate( $query, $request->query->getInt('page', 1), 15 ); } }
    
        
            {{ knp_pagination_render(services, '/pagination/bootstrap_v5_pagination.html.twig') }}