Custom pagination in Magento or pagination for any custom collection or any custom module
Write This code in your Block File :
public function __construct(){
parent::__construct();
$this->setTemplate('moduleName/moduleName.phtml');
// like $this->setTemplate('category/brands.phtml');
$myCollection = Mage::getModel('moduleName/moduleModel')->getCollection();
// like $myCollection = Mage::getModel('catalog/product')->getCollection();
$this->setMyCollection($myCollection);
}
public function getPagerHtml(){
return $this->getChildHtml('pager');
}
public function _prepareLayout(){
parent::_prepareLayout();
$pager = $this->getLayout()
->createBlock('page/html_pager', 'anyname.related.to.your.project')
->setCollection($this->getMyCollection());
$this->setChild('pager', $pager);
$this->getMyCollection()->load();
return $this;
}
And Write this code in your moduleName.phtml file where you want to see the pagination
<?php echo $this->getPagerHtml(); ?>;
That's it... Enjoy Chandresh rana's Coding.... :)
2 comments:
It's good. I have doubt about that. How to build the controller function for pagination?
it is working f9 bt the problem is that it show all products . I want 5 products per page that is not working
Post a Comment