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类。
相关文章
- 实习笔记:java页面的增删改查,分页,模糊查询
- Mongo 分页查询详解程序员
- MySQL实现高效的分页模糊查询(mysql分页模糊查询)
- 实现MySQL分页:实现轻松分页功能(mysql分页类)
- Oracle数据分页技巧:轻松处理海量数据(oracle数据的分页)
- SQL Server数据分页处理技巧(sqlserver中分页)
- MySQL多表查询优化实践:从分页查询开始(mysql多表分页查询)
- 深入了解MySQL中Size分页技术(mysql中size分页)
- MySQL数据库中实现分页加排序的方法(6mysql分页加排序)
- 一个好用的分页函数
- ASP正则函数替换分页后的参数
- asp.net通过aspnetpager为DataList分页
- 基于SqlServer通用分页存储过程的解决方法