magento 自定义pager自定义每页显示多少条记录
2012-01-31 18:38
357 查看
1. 在xml中,定义catalog/product_list_toolbar为xxxx/xxxxter_toolbar
2. 继承Mage_Catalog_Block_Product_List_Toolbar,重写getLimit(),里面是自定义的记录数
3. 继承Mage_Catalog_Block_Product_List, 重写 _getProductCollection()。
<xxxx_xxxxter_index> <reference name="root"> <action method="setTemplate"><template>page/3columns.phtml</template></action> </reference> <reference name="content"> <block type="xxxx/xxxxter_index" name="xxxx_index" template="bysoft/xxxx/xxxxter/index.phtml"> <block type="xxxx/xxxxter_list" name="product_list" template="bysoft/xxxx/xxxxter/list.phtml"> <!-- <action method="addReviewSummaryTemplate"><type>default</type><template>review/helper/su.phtml</template></action> --> <block type="xxxx/xxxxter_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> <block type="page/html_pager" name="product_list_toolbar_pager"> </block> </block> <action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action> <action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action> <action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action> <action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action> <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action> <action method="setToolbarBlockName"><name>product_list_toolbar</name></action> </block> </block> </reference> </xxxx_xxxxter_index>
2. 继承Mage_Catalog_Block_Product_List_Toolbar,重写getLimit(),里面是自定义的记录数
class AAA_Xxx_Block_Xxxter_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar { /** * Get specified products limit display per page * * @return string */ public function getLimit() { return Mage::helper('Aaa_Xxx')->getXxxterListingNumber(); } }
3. 继承Mage_Catalog_Block_Product_List, 重写 _getProductCollection()。
<?php class Aaa_Xxx_Block_Xxxter_List extends Mage_Catalog_Block_Product_List { protected function _getParams($param=null) { if($param) return Mage::app()->getRequest()->getParam($param); else return Mage::app()->getRequest()->getParams(); } /** * Retrieve loaded category collection * * @return Mage_Eav_Model_Entity_Collection_Abstract */ protected function _getProductCollection() { $p = $this->_getParams('p'); if(empty($p)){ $p = 1; } $this->_productCollection=Mage::getResourceModel('catalog/product_collection') ->addStoreFilter() ->setCurPage($p) ->setPageSize(Mage::helper('Aaa_Xxx')->getXxxterListingNumber()) ->addAttributeToSelect("*"); return $this->_productCollection; } }
相关文章推荐
- 首先要定义四个变量: int pageSize:每页显示多少条记录 int pageNow:希望显示第几页 int pageCount:一共有多少页 int rowCount:一共有多少条记录 说明:
- 毕业设计(二十一)---后台管理添加查询方法,按照xxx,升序/降序,每页显示X条记录
- 使用存储过程查询并按每页10条记录分页显示图书借阅纪录
- 用户可以设置每页显示记录数的分页程序
- GridView自定义列(也就是说不管数据源是多少列的,都只按照你需要的列来显示)
- 记录几个比较有用的自定义viewpager
- 使用DataPager 显示记录数,分页
- dede查询列表中单独显示查到了多少条记录
- ViewPager自定义indicator指示器,这里是做一下记录,以免忘记
- RDLC报表:每页显示N条记录
- 自定义对话框,使弹出的对话框变为Viewpager加tab显示。
- easyui自定义扩展视图实现功能--------datagrid返回记录为0时显示“没有记录”
- 毕业设计(二十一)---后台管理添加查询方法,按照xxx,升序/降序,每页显示X条记录
- RDLC报表:每页显示N条记录
- 自定义viewpager与自定义imageview实现图片显示
- jquery分页组件(每页显示多少条)
- extJS控件之每页显示N条记录
- jquery datatables如何去掉搜索框和每页显示多少条数据
- Android仿天猫搜索历史记录显示自定义布局
- ViewPager结合自定义View产生滑动pager下方有效圆点变动显示的效果