简体   繁体   English

PagerFanta问题:setMaxPerPage不起作用

[英]PagerFanta issue: setMaxPerPage not working

i trying to create a paginator when i display products but the $paginator->setMaxPerPage() and $paginator->setCurrentPage() are not working : 我尝试在显示产品时创建分页器,但$ paginator-> setMaxPerPage()和$ paginator-> setCurrentPage()无法正常工作:

my repository method : 我的存储库方法:

 public function findLatestBySubcategAndTaxon($ids, $taxon_id)
{
    $sids = implode(",", $ids);



    $manager = $this->getEntityManager();

    $res = $manager->createQuery('
            select p from AppBundle:Product p
            join p.subcategories sp WITH sp.id in (:ids)
            group by p.id
            having GROUP_CONCAT(sp.id order by sp.id separator \',\') = :sids
        ')
        ->setParameter('ids', $ids)
        ->setParameter('sids',$sids);


        //$products = $res->getResult();

    $paginator = new Pagerfanta(new DoctrineORMAdapter($res, false));
    $mp= 1;
    $cp=1;
    $paginator->setMaxPerPage($mp); // not working , always return  10 instead of 1
    $paginator->setCurrentPage($cp);// not working , always return  1
    var_dump($paginator->setMaxPerPage($mp));
    //var_dump($paginator);
    //var_dump($paginator);
    //exit();
    return $paginator;

        //return $products;

}

my routing : 我的路线:

app_latest_prod_subcateg_taxon:
path: /products/prodfilter # configure a new path that has all the needed variables
methods: [POST]
defaults:
    _controller: sylius.controller.product:indexAction # you make a call on the Product Controller's index action
    _sylius:
        template: $template
        repository:
            method: findLatestBySubcategAndTaxon # here use the new repository method
            arguments:
                - $ids
                - $taxon_id

twig file : 树枝文件:

<div class="ui four column stackable grid">
<div class="row">


    {{ dump(products) }}
    {{ dump(products.maxPerPage) }}

    {{ dump(products.maxPerPage) }}
    {% if products|length >0 %}
    {% for product in products.getCurrentPageResults() %}
    <div class="column">
        {% include '@App/ProductList/_simpleBox.html.twig' %}
    </div>
    {% if 0 == loop.index % 3 %}
</div>
<div class="row">
    {% endif %}
    {% endfor %}
 {% if products.haveToPaginate %}
        {{ pagerfanta(products) }}
    {% endif %}
    {% else %}
        <div class="ui negative message">
            <i class="close icon"></i>
            <div class="header">
                Oups !
            </div>
            <p>Aucun article trouvés
            </p></div>
    {% endif %}
</div>

and the dump(products) in the yml file return : 并且yml文件中的dump(products)返回:

在此处输入图片说明

the maxPerPage attribut should be 1 !!! maxPerPage属性应为1 !!! where is the problem 问题出在哪儿

Seems to have been an issue with Sylius itself and seemingly it has also been fixed here . Sylius本身似乎是一个问题,而且似乎也已在此处解决 I suggest you update your version of Sylius 我建议您更新您的Sylius版本

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

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