我在显示产品时尝试创建分页器,但 $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 !!!问题出在哪里