3

How can I take a result as an array from PagerFanta in Symfony2.1.1 ?

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

Results of 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
                    ...
                    ...
                    ...

I want to get results as getQuery->getArrayResult();

Dezigo
  • 3,220
  • 3
  • 31
  • 39

2 Answers2

3
  1. I will Do the query

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

    $adapter = new ArrayAdapter($array);
    $pagerfanta = new Pagerfanta($adapter);
    
j0k
  • 22,600
  • 28
  • 79
  • 90
Max Małecki
  • 1,700
  • 2
  • 13
  • 18
0

You must to set hydratation mode to Query from the adapter:

$adapter = new DoctrineORMAdapter($queryBuilder);
$adapter->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY);
$pager = new Pagerfanta($adapter);