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


Put pager.html inside result.phtml instead of toolbar.phtml

我正在尝试使用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()在文件工具栏.phtml中使用:

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

此函数显示默认页面导航,并调用 toolbar.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 中对结果进行分页,而无需所有这些依赖项?

> Uou 可以使用此代码将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();
 ?>