knp Paginator渲染

时间:2016-02-20 22:17:13

标签: php symfony pagination

我在渲染knp paginator时遇到错误:

  

An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Argument 2 passed to Knp\Bundle\PaginatorBundle\Twig\Extension\PaginationExtension::render() must be an instance of Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination, array given, called in C:\wamp\www\TunisiaMall\app\cache\dev\twig\7b\87\136d965ad591aa95bee5c88d324ab4fe15f38a8af882bbdb9ef9f4ac9320.php on line 78 and defined in C:\wamp\www\TunisiaMall\vendor\knplabs\knp-paginator-bundle\Twig\Extension\PaginationExtension.php line 43") in TMallClientBundle:Default:detailBoutique.html.twig at line 29.

这是控制器的代码:

public function boutiqueDetailAction(){


     $em = $this->getDoctrine()->getManager();
    $boutiq = $em->getRepository("TMallEntityBundle:boutique")->findAll();

     $boutique  = $this->get('knp_paginator')->paginate(
    $boutiq,
    $this->get('request')->query->get('page', 1)/*page number*/,
    2/*limit per page*/
);





    return $this->render("TMallClientBundle:Default:detailBoutique.html.twig",array("boutiques"=>$boutiq));
}

1 个答案:

答案 0 :(得分:2)

控制器:

meteor create cool
cd cool
meteor build /root/cool/production --directory --server=wdksw.com:3030
Killedking                                   \

............................................... ............................

看起来像 production

use Symfony\Component\HttpFoundation\Request;
..................................................................

public function boutiqueDetailAction(Request $request) {

    $em = $this->getDoctrine()->getManager();
    //findAll is very slow
    $boutiq = $em->getRepository("TMallEntityBundle:boutique")->findAll();
    //I suggest use queryBuilder
    $boutiq = $em->getRepository("TMallEntityBundle:boutique")>createQueryBuilder('s')->getQuery();

    $boutique  = $this->get('knp_paginator')->paginate(
       $boutiq,
       $request->query->get('page', 1)/*page number*/,
       10 /*limit per page*/
    );

    return $this->render("TMallClientBundle:Default:detailBoutique.html.twig",array("boutiques"=>$boutiq));
}