简体   繁体   English

切换页面Symfony 3时,Knp分页器包无法正常工作?

[英]Knp paginator bundle doesnt work perfectly when switching pages symfony 3?

i have installed the knp paginator bundle in my project and i followed the installation tuto in git hub and then every thing work but there is a problem in my controller i fixed the limit per page to 1 item and i find when im switching page it shows me 2 items 我已经在项目中安装了knp paginator捆绑软件,并且在git hub中遵循了安装tuto,然后一切正常,但是控制器中存在问题,我将每页的限制固定为1,当我切换页面时我发现我2件

this is my controller 这是我的控制器

public function membreGroupeAction(Request $request)
{
    $em = $this->getDoctrine()->getManager();
    $str = $em->getRepository("GroupGroupBundle:Groupe")->findOneBy(array('id'=>1));
    $member = $em->getRepository("GroupGroupBundle:Groupe")->getmemberlist($str->getMembres());

    $paginator  = $this->get('knp_paginator');
    $res = $pagination = $paginator->paginate(
        $member, /* query NOT result */
        $request->query->getInt('page', 1),       /*page number*/
        $request->query->getInt('page', 1)        /*limit per page*/
    );


    return $this->render('@GroupGroup/layout/membres.html.twig',array("mem"=>$res));

}

and this is my twig view 这是我的树枝观

 {% extends '@GroupGroup/Group/groupe_mur_base.html.twig' %}
 {% block panel %}

<div class="jumbotron list-content" style="display: block;">
    <ul class="list-group">
        <li href="#" class="list-group-item title">
            Liste des Membres
        </li>
        {% for i in  mem %}
            <li href="#" class="list-group-item text-left" id="listmembre" style="display: block;">

                <div class="image">
                    <img class="img-thumbnail" src="{{ i.profile_pic }}">
                    <span id="membername">{{ i.nom }} {{ i.prenom }}</span>
                    <div><button id="btnajout" class="btn btn-primary">Ajouter</button></div>

                </div>
                <div class="break"></div>
            </li>
        {% endfor %}




        <li href="#" class="list-group-item text-left">
            <div class="navigation text-center" >
                {{ knp_pagination_render(mem) }}
            </div>
        </li>
    </ul>
</div>
  {% endblock %}

this is my output in the first page 这是我在第一页中的输出 第一页

and this is my output after clicking to the 2nd page 这是我点击第二页后的输出 第二页输出

You aren't setting the limit to 1, you are setting it to the current page. 您没有将限制设置为1,而是将其设置为当前页面。

$res = $pagination = $paginator->paginate(
    $member, /* query NOT result */
    $request->query->getInt('page', 1),       /*page number*/
    $request->query->getInt('page', 1) // <-- right here
);

Change the marked line to just 1 and you should be fine. 将标记的行更改为仅1 ,就可以了。

this is the right code i found out my error everything is working perfectly now 这是正确的代码,我发现了我的错误,现在一切正常

$paginator  = $this->get('knp_paginator');
    $res = $pagination = $paginator->paginate(
        $member, /* query NOT result */
        $request->query->getInt('page', 1),       /*page number*/
        $request->query->getInt('limit', 1)        /*limit per page*/
    );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM