0

我在显示产品时尝试创建分页器,但 $paginator->setMaxPerPage() 和 $paginator->setCurrentPage() 不起作用:

我的存储库方法:

 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;

}

我的路由:

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

树枝文件:

<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>

并且 yml 文件中的转储(产品)返回:

在此处输入图像描述

maxPerPage 属性应该是 1 !!!问题出在哪里

4

1 回答 1

0

似乎是 Sylius 本身的问题,并且似乎也已在此处修复。我建议你更新你的 Sylius 版本

于 2017-02-17T15:23:30.210 回答