【发布时间】:2014-10-04 16:18:38
【问题描述】:
我有一个问题,knp 分页器只能这样工作:
$em = $this->get('doctrine.orm.entity_manager');
$dql = "SELECT a FROM MainArtBundle:Art a";
$query = $em->createQuery($dql);
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1) /*page number*/,
8 /*limit per page*/
);
但不是这样:
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('MainArtBundle:Art')->findAll();
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$entities,
$this->get('request')->query->get('page', 1) /*page number*/,
/*limit per page*/
);
为什么会这样?我不明白。
这是我的树枝电话:
<li>{{ knp_pagination_sortable(paginator, 'Oldest', 'a.id', {'direction': 'desc'}) }}</li>
问候迈克尔
【问题讨论】:
-
我几乎有同样的问题。我无法直接对我的实体进行分页,而无需构建某种新查询。我的意思是我已经有了我喜欢的查询和实体用法,我只是想为其添加分页,而文档仅显示了如何以一种方式进行操作..正如您的问题所表明的那样..奇怪的是,在我的情况下,它正在滴流到这个错误,这是非常错误的引导..我想将它添加到这个主题以提高搜索能力
Attempted to call method "getTemplate" on class "Symfony\Component\HttpFoundation\JsonResponse". (500 Internal Server Error) -
in vendor/knplabs/knp-paginator-bundle/Twig/Extension/PaginationExtension.php at line 56$template ?: $pagination->getTemplate(),
标签: php symfony doctrine-orm pagination knppaginator