zoukankan      html  css  js  c++  java
  • How to use pagination in Magento

    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 :

    <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');?>
    
     
    作者:冯亮
             
    能力有限,水平一般。如有错误,欢迎指正
  • 相关阅读:
    每周总结13
    每周总结12
    每周总结11
    每周总结10
    每周总结9
    启明5-1总结
    启明4-30团队进度博客
    期末总结
    每日日报2021.6.11
    每日日报2021.6.10
  • 原文地址:https://www.cnblogs.com/fengliang/p/3660635.html
Copyright © 2011-2022 走看看