Knp Paginator不适用于Query

时间:2013-06-24 22:30:19

标签: paginator symfony-2.3

我正在设置knp paginator,我的作曲家设置为“knplabs / knp-paginator-bundle”:“2.3。*”但是它不适用于Query对象。

这是我的问题:

public function getCommentariesByUser(User $user) {
        $qb = $this->createQueryBuilder('c');
        $qb->innerJoin('c.item', 'i');

        $qb->andWhere($qb->expr()->eq('i.user', ':user'))
               ->setParameter(':user', $user);

        $qb->andWhere($qb->expr()->neq('c.user', ':user1'))
               ->setParameter(':user1', $user);

       return $qb->getQuery();
}

我在行动中如何称呼它:

public function commentariesAction($page) {
    $user = $this->getUser();
    $commentaryRepository = $this->getDoctrine()->getRepository('My\MyBundle\Entity\Commentary');
    $query  = $commentaryRepository->getCommentariesByUser($user);

    $paginator  = $this->get('knp_paginator');
    $pagination = $paginator->paginate(
        $query,
        $page/*page number*/,
        15/*limit per page*/
    );

    return array('pagination' => $pagination);
}

它根本不显示结果,但是如果我把$ query-> execute()它可以工作。怎么了?

1 个答案:

答案 0 :(得分:0)

目前可以使用上一代码的下一个paginator包组合来实现:

"knplabs/knp-components": "1.2.1",
"knplabs/knp-paginator-bundle": "~2.3"