zl程序教程

您现在的位置是:首页 >  其它

当前栏目

magento 分页

分页
2023-09-14 08:59:48 时间

我使用我的消息插件作为例子,我是参考magento的tag wishlist order如何添加pager代码的。你直接套用本教程中的代码,基本就可以实现给你的插件添加分页的功能了。

 在插件block的php文件中


?php   class Hellokeykey_Messagesbox_Block_Messagesbox extends Mage_Core_Block_Template       public function __construct()       {           parent::__construct();           /*声明我的collection*/           $this- _collection = Mage::getModel(messagesbox/messagesbox)- getCollection();           /*对我的collection进行筛选,我将结果按照建立时间进行了逆向排序,所以最近添加的会显示在前面。并且只显示激活状态的消息*/           $this- _collection- setOrder(created_time, DESC)- addFilter(status,array(status =  1));       }       public function count()       { /* 判断是否为空,在我们的phtml输出前判断下,为空的话说出一段html作为提示 */           return $this- _collection- getSize();       }       public function getToolbarHtml()       { /* 获得toobar,在phtml中用到 */           return $this- getChildHtml(toolbar);       }       protected function _prepareLayout()       { /* 定义我们的toobar */           $toolbar = $this- getLayout()- createBlock(page/html_pager, messages.toolbar)- setCollection($this- _getCollection());           /* messages.toolbar 是随便写的*/                      $this- setChild(toolbar, $toolbar);           return parent::_prepareLayout();       }       /*protected function _prepareLayout(){ //查询条件          parent::_prepareLayout();          $brand_id= $this- getRequest()- getParam(id);          $collection = Mage::getModel(catalog/product)- getCollection();          if (is_numeric($brand_id)) {               $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;               }*/       protected function _getCollection()       {           return $this- _collection;       }       public function getCollection()       {           return $this- _getCollection();       }  
div id="_mcePaste" !-- table -- /div    div id="_mcePaste" ?php if($this- count()): /*判断是否为空*/? /div    div id="_mcePaste" ?php echo $this- getToolbarHtml(); /*获得分页工具条*/? /div    div id="_mcePaste" table id="my-messages-table" /div    div id="_mcePaste" col width="12%" / /div    div id="_mcePaste" col width="68%" / /div    div id="_mcePaste" col width="12%" / /div    div id="_mcePaste" col width="8%" / /div    div id="_mcePaste" thead /div    div id="_mcePaste" tr /div    div id="_mcePaste" th ?php echo $this- __(Date(m/d/y)) ? /th /div    div id="_mcePaste" th ?php echo $this- __(Messages) ? /th /div    div id="_mcePaste" th ?php echo $this- __(Download) ? /th /div    div id="_mcePaste" th ?php echo $this- __(Link) ? /th /div    div id="_mcePaste" /tr /div    div id="_mcePaste" /thead /div    div id="_mcePaste" tbody /div    div id="_mcePaste" ?php foreach ($this- getCollection() as $i= $message): /* 这里是最重要的地方,一定要用$this- getCollection()来获得Collection */ ? /div  
谈谈分页插件的配置与使用 组装式开发的核心是一个个可复用的组件,每一个组件中都有一些常用的插件或者工具,在这里简单聊一聊分页插件PageHelper在mybatisplus框架中的使用。
       在我们平时浏览网页时,经常会遇到网页里条目很多的情形,这时就会用到分页展示的功能。那么,在Django中,是如何实现网页分类的功能的呢?答案是Paginator类。