E
E
Eugene Pukha2018-03-09 12:18:49
symfony
Eugene Pukha, 2018-03-09 12:18:49

What can this bug in pagination mean?

Good day to all.
I'm trying to organize the output of a list with pagination. I use the plugin https://packagist.org/packages/pagerfanta/pagerfanta. The code looks like this:

public function list($page = 1, $limit = 1)
{
    $pager = new Pagerfanta(new DoctrineORMAdapter($this->getDoctrine()
        ->getRepository(User::class)
        ->createQueryBuilder('u')
        ->select('u.id', 'u.username', 'u.email', 'u.isActive')
        ->orderBy('u.username', 'ASC')));
    $pager->setMaxPerPage($limit)->setCurrentPage($page);

    dump($pager->getCurrentPageResults());

    return $this->render('pages/admin/users/list.html.twig', ['users' => $pager]);
}

The error pops up in this place:
dump($pager->getCurrentPageResults());
and looks like this:
RuntimeException:
The Paginator does not support Queries which only yield ScalarResults.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-04-13
@summoner2015

Use a different adapter like DoctrineDbalAdapter with a little code change.
In your example, a "partial" selection of the object, namely just a few properties of the User class. That is why the result will not be an object, but an array. Pagefanta is telling you exactly that.
Actually, either choose complete objects, or incomplete arrays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question