Php knp分页器渲染

Php knp分页器渲染,php,symfony,pagination,Php,Symfony,Pagination,渲染knp paginator时出现错误: 在呈现模板的过程中引发了异常(“可捕获的致命错误:传递给Knp\Bundle\PaginatorBundle\Twig\Extension\PaginationExtension::render()的参数2”)必须是Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination的实例,数组给定,在C:\wamp\www\TunisiaMall\app\cache\dev\twig\7b\87\136D96

渲染knp paginator时出现错误:

在呈现模板的过程中引发了异常(“可捕获的致命错误:传递给Knp\Bundle\PaginatorBundle\Twig\Extension\PaginationExtension::render()的参数2”)必须是Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination的实例,数组给定,在C:\wamp\www\TunisiaMall\app\cache\dev\twig\7b\87\136D965AD591AA95BEE5C88D324AB4FE15F38A8AF882BBB9EF9F4AC9320.php第78行调用,并在C:\wamp\www\TunisiaMall\vendor\knplabs\KNPG\Knp paginator Bundle\twig\Extension\PaginationExtension.php第4行定义TMallClientBundle中的3“:默认值:第29行的detailboutine.html.twig。

以下是控制器的代码:

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));
}
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));
}
控制器:

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));
}
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));
}

看起来像您的
视图

<table>
   <tr>
      <th>Id'</th>
      <th>Title'</th>
      <th>Date</th>
   </tr>
  {% for article in pagination %}
   <tr>
      <td>{{ article.id }}</td>
      <td>{{ article.title }}</td>
      <td>{{ article.date | date('Y-m-d') }}</td>
   </tr>
  {% endfor %}
</table>

<div class="navigation">
   {{ knp_pagination_render(pagination) }}
</div>

身份证
标题'
日期
{%用于分页%中的项目}
{{article.id}
{{article.title}}
{{article.date}date('Y-m-d')}
{%endfor%}
{{knp_分页}

视图中的问题。你能展示你的小树枝模板吗?