在任何块的集合中添加分页
-
16-10-2019 - |
题
我有许多集合,它们的块将内容输出到前端路线(我的帐户,前端功能)。
我需要为其中一些。我知道分页方法存在于集合上,但是还有一种方法可以处理问题部分吗?我讨厌重塑轮子...
解决方案
实际上很简单。
在调用您的集合渲染的主要块中,添加以下内容:
protected function _prepareLayout()
{
parent::_prepareLayout();
$pager = $this->getLayout()->createBlock('page/html_pager', 'your.custom.blockname.pager')
->setCollection($this->getCollection()); //call your own collection getter here, name it something better than getCollection, please; *or* your call to getResourceModel()
$this->setChild('pager', $pager);
return $this;
}
public function getPagerHtml()
{
return $this->getChildHtml('pager');
}
默认情况下,这将限制您的收集到10次!甜的!!
然后,从与收藏集关联的模板PHTML中,添加Pager控件,通过回声我们的其他方法的输出, getPagerHtml
:
<?php echo $this->getPagerHtml(); ?>
资料来源:经验。而且, sales/order_history
在Magento的街区。
其他提示
我使用了此内部块类(它是mage_catalog_block_navigation):
$pager = new Mage_Page_Block_Html_Pager();
$pager->setLimit(100)->setCollection(...getCollection());
$this->setChild('pager', $pager);