dousi2029 2017-06-18 16:54
浏览 50
已采纳

Knp Pagination Bundle不会在同一个重新查看的视图上显示分页

I have {{ knp_pagination_render(pagination1) }} on view InfCustumersBundle:Faktura:indexoryginal.html.twig

This code show me paginarion:

public function indexoryginalAction(Request $request) {              
            $em = $this->getDoctrine()->getManager();
            $req = $em->getRepository('...:Faktura');
            $qb = $req->createQueryBuilder('p');
            $search = $qb
                        .
            .
                    ->getQuery();              
           $form = $this->createFormBuilder()
               .
           .
                ->getForm();
        $paginator = $this->get('knp_paginator');
        $pagination1 = $paginator->paginate(
                $search, $request->query->get('page', 1)/* page number */, 5/* limit per page */
        );

        return $this->render('InfCustumersBundle:Faktura:indexoryginal.html.twig', array(
                    'pagination1' => $pagination1,
                    'form' => $form->createView()
        ));

and this work fine, but code bellow don't show pagination tags. Only the first 3 items. Where I made a mistake ?

public function indexAction(Request $request, $type = 1) {

        $data = array();
        $form = $this->createFormBuilder()
                .
        .   
                ->getForm();
        if ($request->isMethod('GET')) {
            $form->handleRequest($request);
            if ($form->isSubmitted() && $form->isValid()) {
            $data = $form->getData();
                    $name = ($data['for'] == 'name' ? true : false);
                if ($name) {
                    return $this->Name($form);
                } 
            }          
                return $this->redirect($this->generateUrl('faktura_oryginal', array(
                                    $this->get('session')->getFlashBag()->add('error', 'error')
                )));          
        }

protected function Name($form) {

        $em2 = $this->getDoctrine()->getManager();
        $req = $em2->getRepository('InfCustomersBundle:Faktura');
        $qb = $req->createQueryBuilder('p');

        $query2 = $qb
                .
                .
                ->getQuery();

        $entities2 = $query2->getResult();
        if ($entities2) {

            $paginator = $this->get('knp_paginator');
            $request = $this->get('request_stack');
            //  $request = $this->getRequest();
            $pagination1 = $paginator->paginate(
                    $query2, $request->getCurrentRequest()->query->get('page', 1)/* page number */, 3/* limit per page */
            );          
                return $this->render('InfCustumersBundle:Faktura:indexoryginal.html.twig', array(
                            'pagination1' => $pagination1,
                            'form' => $form->createView()
                ));          
        } else {
                return $this->redirect($this->generateUrl('faktura_oryginal', array(                               $this->get('session')->getFlashBag()->add('error', 'error')
                )));         
            }
        }
    }
  • 写回答

1条回答 默认 最新

  • dongqun1656 2017-06-21 19:47
    关注

    I found a solution

    I changed:

    $entities2 = $query2->getResult();
            if ($entities2) {
    

    to

        $pagination1 = $paginator->paginate(
                $query2, $request->getCurrentRequest()->query->get('page',1),25);
        if (count($pagination1) > 0) {
    

    and now is working well

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码