gpt4 book ai didi

php - 带有 findAll() 方法的 Knp 分页器

转载 作者:可可西里 更新时间:2023-11-01 13:11:07 30 4
gpt4 key购买 nike

我有一个问题,knp paginator 只能像这样工作:

    $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*/
);

为什么会这样?我不明白。

这是我的 Twig 调用:

<li>{{ knp_pagination_sortable(paginator, 'Oldest', 'a.id', {'direction': 'desc'}) }}</li>

问候迈克尔

最佳答案

findAll() 与 Knp_paginator 兼容,你只需要将它提供给你的分页器:

$query = $em->getRepository('Acme\FOOBundle\Entity\BAR')->findAll();
$paginator = $this->get('knp_paginator');
requests = $paginator->paginate(
$query,
$this->get('request')->query->get('page', 1),
5
);

关于php - 带有 findAll() 方法的 Knp 分页器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26194680/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com