1

我正在尝试使用pager.phtml文件对我的result.phtml文件进行分页创建自定义块:

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

但我收到以下错误:

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


在 Magento 的默认结构中,函数$this->getPagerHtml()在文件 toolbar.phtml 中使用

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

此函数显示默认页面导航和工具栏.phtml文件被调用:

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

由函数$this->getToolbarHtml()调用 list.phtml文件:

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

通过函数$this->getProductListHtml()


我如何使用函数$this->getPagerHtml()(或者,以某种方式使用分页)直接在result.phtml中对结果进行分页,而不需要所有这些依赖项?

4

1 回答 1

0

您可以使用此代码添加pager到您的result.phtml. 您必须使用该setCollection函数提供集合。

_getProductCollection()是类中的一个受保护函数Mage_CatalogSearch_Block_Result,并获取当前产品集合。

<?php 
    $layout = Mage::getSingleton('core/layout');
    $pager = $layout->createBlock('page/html_pager');
    $pager->setCollection($this->_getProductCollection());
    echo $pager->toHtml();
 ?> 
于 2017-10-16T21:42:24.497 回答