duanmie9682 2015-01-14 20:04 采纳率: 100%
浏览 44

将pager.html放在result.phtml而不是toolbar.phtml中

I'm trying to put a pagination on my result.phtml file using pager.phtml file creating a custom block:

echo $this->getLayout()->createBlock('page/html_pager', 'bottom.pager')->toHtml();

But i get the following error:

Fatal error: Call to a member function getSize() on a non-object


On Magento's default structure, the function $this->getPagerHtml() is used inside the file toolbar.phtml:

/app/design/frontend/base/default/template/catalog/product/list/toolbar.phtml

This function shows the default page navigation and the toolbar.phtml file is called on:

app/design/frontend/base/default/template/catalog/product/list.phtml

by the function $this->getToolbarHtml() and the list.phtml file is called on:

app/design/frontend/base/default/template/catalogsearch/result.phtml

by the function $this->getProductListHtml().


How can i use the function $this->getPagerHtml() (or, somehow, use pagination) for paginate my results directly inside result.phtml without need of all these dependencies?

  • 写回答

1条回答 默认 最新

  • duanhuang4841 2017-10-16 21:42
    关注

    Uou can use this code to add pager to your result.phtml. You must provide the collection using the setCollection function.

    _getProductCollection() is a protected function from the class Mage_CatalogSearch_Block_Result, and gets current product collection.

    <?php 
        $layout = Mage::getSingleton('core/layout');
        $pager = $layout->createBlock('page/html_pager');
        $pager->setCollection($this->_getProductCollection());
        echo $pager->toHtml();
     ?> 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?