3

如何将结果作为来自 Symfony2.1.1 中 PagerFanta 的数组?

        $adapter = new \Pagerfanta\Adapter\DoctrineORMAdapter($query);
        $pager = new \Pagerfanta\Pagerfanta($adapter);
        $pager->setMaxPerPage(45);
        $data = $pager->getCurrentPageResults();

结果print_r($data);

ArrayIterator Object
(
    [storage:ArrayIterator:private] => Array
        (
            [0] => Trucking\MainBundle\Entity\Sparcs Object
                (
                    [id:Trucking\MainBundle\Entity\Sparcs:private] => 77940
                    [container:Trucking\MainBundle\Entity\Sparcs:private] => MEDUUUU
                    ...
                    ...
                    ...

我想得到结果getQuery->getArrayResult();

4

2 回答 2

3
  1. 我会做查询

    $array = $query->getResult(Query::HYDRATE_ARRAY);
    
  2. 使用 ArrayAdapter

    $adapter = new ArrayAdapter($array);
    $pagerfanta = new Pagerfanta($adapter);
    
于 2012-09-12T07:41:42.193 回答
0

您必须将水合模式设置为从适配器查询:

$adapter = new DoctrineORMAdapter($queryBuilder);
$adapter->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY);
$pager = new Pagerfanta($adapter);
于 2021-11-26T23:00:59.747 回答