Adh*_*esh 6 collections pagination magento
我通过向Varien_Data_Collection集合对象添加项目来创建集合.
$collection = new Varien_Data_Collection();
foreach($array_of_products as $productId){
$collection->addItem(Mage::getModel('catalog/product')->load($productId));
}
Run Code Online (Sandbox Code Playgroud)
但是,当此对象传递给Magento寻呼机块时,如下所示,它会破坏我的自定义页面中的分页.
$pager = $this->getLayout()->createBlock('page/html_pager', 'retailerfe.analysis.pager')
->setCollection($collection);
Run Code Online (Sandbox Code Playgroud)
PS从Mage :: getModel('module/modelname') - > getCollection()等模型集合中获取的集合从未出现过问题.它只是通过向Varien_Data_Collection对象添加项而创建的集合.
寻呼机正在调用setPageSize您的集合 - 如果您追踪它 - 仅用于getLastPageNumber.这意味着寻呼机可以准确地显示页数,但就是这样.Varien_Data_Collection_Db实际上,通过将它们作为LIMITSQL 的子句呈现,它实际上对当前页面编号和大小做了任何事情.
要创建一个尊重页面条件的集合,您必须为该类创建一个后代.对于想法,请查看它的来源Varien_Data_Collection_Filesystem和实现方式loadData.
我刚刚重新阅读了你的问题并意识到你可以这样做:
$collection = Mage::getModel('catalog/product')->getCollection()
->addIdFilter($array_of_products);
Run Code Online (Sandbox Code Playgroud)
这个系列的页面会非常愉快.
| 归档时间: |
|
| 查看次数: |
5662 次 |
| 最近记录: |