Symfony pagination error here are no registered paths for namespace "KnpPaginator"

902 views Asked by At

I'm using knp-paginator and I have a controller

public function offers(Request $request)
{
    $locations= $this->getDoctrine()->getRepository(Oobject::class)->findAll();

    $paginator = $this->get('knp_paginator');
    dump(get_class($paginator));
    $result = $paginator->paginate(
        $locations,
        $request->query->getInt('page', 1),
        $request->query->getInt('limit', 3)
    );

    return $this->render('main/offers.html.twig', array
        ('controller_name' => 'MainController',
        'locations' =>$result)
    );
}

Everything works as expected until I add pagination into html.twig file like so:

<div>
    {{knp_pagination_render(locations)}}
</div>

I get an error "There are no registered paths for namespace "KnpPaginator"." Any idea how to fix this?

2

There are 2 answers

0
philmtp On

I fixed it by adding this path in twig.yaml file:

paths:
    '%kernel.project_dir%/vendor/knplabs/knp-paginator-bundle/templates':KnpPaginator
0
Mohamed CHIBANI On

in twig.yaml file add:

twig:
    paths: 
       '%kernel.project_dir%/vendor/knplabs/knp-paginator-bundle/templates': KnpPaginator