1
2
3
4
5
6
7
8
9
10
11
12
13
14 |
classYour_Module_Block_Entityname_ListextendsMage_Core_Block_Template { protected
function _construct(){ // We get our collection through our model parent::_construct(); // Instantiate a new Pager block $this ->_entities =Mage::getModel( ‘your_module/entityname‘ )->getCollection()->setOrder( ‘created_at‘ , ‘desc‘ ); // /!\ The limit must be set before the collection $pager
=newMage_Page_Block_Html_Pager(); // We set our limit (here an integer store in configuration). // Add our Pager block to our current list block $pager ->setLimit((int)Mage::getStoreConfig( ‘your_module/entityname/pagination‘ ))->setCollection( $this ->_entities); $this ->setChild( ‘pager‘ , $pager ); } } |
You just need now to include the
call in your template (phtml) file :
1
2
3
4
5
6
7
8
9
10
11 |
<divclass= "your_module_entities" > <?php foreach ( $this ->_entities as
$entity ):?> <divclass= "entity" > <h2> <?php echo
$entity ->getAttribute1();?> </h2> <p> <?php echo
$entity ->getAttribute2();?> </p> </div> <?php endforeach ;?></div><?php echo
$this ->getChildHtml( ‘pager‘ );?> |
How to use pagination in Magento,布布扣,bubuko.com
How to use pagination in Magento
原文:http://www.cnblogs.com/fengliang/p/3660635.html