ask | one |
---|---|
Bundled Version | x.y.z |
Symfony version | 6.0.4 |
PHP version | 8.1.6 |
Hi,
I am asking for help creating pagination for the index. I tried many methods but failed with everyone. Below I attach the data for this project:
View MySql and symfony components
Implementing the controller of the pager
What do I have to change to make it work?
CodeKnpPaginator
mistake
P粉7207169342024-02-22 09:00:08
I have this pagination implementation in my old project, take a look maybe you can find something that works for you.
/** * @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') }}