Symfony2,PagerFanta结果

时间:2012-09-12 07:25:36

标签: symfony doctrine pagerfanta

如何在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();

的结果

1 个答案:

答案 0 :(得分:3)

  1. 我会做查询

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

    $adapter = new ArrayAdapter($array);
    $pagerfanta = new Pagerfanta($adapter);