2016-11-11 61 views
0

我試圖建立一個分頁程序,當我展示產品,但$ paginator-> setMaxPerPage()和$ paginator-> setCurrentPage()不工作:PagerFanta問題:setMaxPerPage不工作

我的倉庫方法:

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文件返回轉儲(產品):

enter image description here

的maxPerPage attribut應該是1!問題出在哪裏

回答

0

似乎是Sylius本身的問題,看起來它也被修復了here。我建議你更新你的Sylius版本