我正在使用knp-paginator 并且我有一个控制器
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)
);
}
一切都按预期工作,直到我将分页添加到 html.twig 文件中,如下所示:
<div>
{{knp_pagination_render(locations)}}
</div>
我收到错误"命名空间"KnpPaginator"没有注册路径。 知道如何解决这个问题吗?
我通过在文件中添加此路径来修复它twig.yaml
:
paths:
'%kernel.project_dir%/vendor/knplabs/knp-paginator-bundle/templates':KnpPaginator
在 twig.yaml 文件中添加:
twig:
paths:
'%kernel.project_dir%/vendor/knplabs/knp-paginator-bundle/templates': KnpPaginator