ブロックのコレクションにページネーションを追加します
-
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から、他の方法の出力をエコーすることにより、ポケットベルコントロールを追加します。 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);
所属していません magento.stackexchange