Implementing knpPaginator in symfony 6
P粉982054449
P粉982054449 2024-02-21 10:23:06
0
1
378

ask one
Bundled Version x.y.z
Symfony version 6.0.4
PHP version 8.1.6

Support Issues

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粉982054449
P粉982054449

reply all(1)
P粉720716934

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
        );
    }
}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template