使用magento的分页



使用magento的分页

在一个BLOCK的类里面
protected function _prepareLayout(){
parent::_prepareLayout();
$brand_id= $this->getRequest()->getParam(‘id’);
if (is_numeric($brand_id)) {
$collection = Mage::getModel(‘catalog/product’)->getCollection();
$collection->addFieldToFilter(‘brand’, array(‘eq’ => $brand_id));

$pager = $this->getLayout()->createBlock(‘page/html_pager’)
->setTemplate(‘page/html/test.pager.phtml’)
->setLimit($this->page_size)
->setCollection($collection);
$this->setChild(‘pager’, $pager);
}
return $this;

}
public function getPagerHtml(){
return $this->getChildHtml(‘pager’);
}

调用就很简单啦。。对应的.phtml
<?php echo $this->getPagerHtml()?>