如何在Magento中的非EAV模型中使用setPage()进行分页/限制?

如何在Magento中的非EAV模型中使用setPage()进行分页/限制?,magento,Magento,我需要获得$collection->setPage(0,10)在我的非EAV模型上工作,但它不工作。我已经试过了,$matches->getSelect()->setPage(0,10)并且它没有帮助 方法setPage()仅适用于Magento中基于EAV的集合,因为它是在Mage\u EAV\u Model\u Entity\u collection\u Abstract类中定义的 public function setPage($pageNum, $pageSize) { $thi

我需要获得
$collection->setPage(0,10)在我的非EAV模型上工作,但它不工作。我已经试过了,
$matches->getSelect()->setPage(0,10)并且它没有帮助

方法
setPage()
仅适用于Magento中基于EAV的集合,因为它是在
Mage\u EAV\u Model\u Entity\u collection\u Abstract
类中定义的

public function setPage($pageNum, $pageSize)
{
    $this->setCurPage($pageNum)
        ->setPageSize($pageSize);
    return $this;
}
如您所见,它是一个很好的速记工具,可用于基于EAV的集合。对于非基于EAV的集合,您可以在集合类中创建自己的版本,或者在初始化集合时使用更详细的语法在客户端代码中设置页码和大小:

$collection->setCurPage($pageNum)
           ->setPageSize($pageSize)
;
公共函数updateIndex()
{
$productsCollection=Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect(数组(“名称”、“图像”、“url_键”、“价格”、“可见性”);
$productsCollection->setPageSize(100);
$pages=$productsCollection->getLastPageNumber();
$currentPage=1;
做{
$productsCollection->setCurPage($currentPage);
$productsCollection->load();
foreach($productsCollection作为$\u产品){
$insertData=数组(
'entity_id'=>$\u product->getId(),
'title'=>$\u product->getName(),
'image'=>$\u product->getImage(),
'url'=>$\u product->getUrlKey(),
“价格”=>$\u产品->getFinalPrice(),
);
$this->\u getWriteAdapter()->insertOnDuplicate(
$this->getTable('atwix_声纳/建议'),
$insertData,
数组(‘标题’、‘图像’、‘url’、‘价格’)
);
}
$currentPage++;
//清除收集并释放内存
$productsCollection->clear();
}而($currentPage
public function updateIndex()
{
    $productsCollection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect(array('name', 'image', 'url_key', 'price', 'visibility'));

    $productsCollection->setPageSize(100);

    $pages = $productsCollection->getLastPageNumber();
    $currentPage = 1;

    do {
        $productsCollection->setCurPage($currentPage);
        $productsCollection->load();

        foreach ($productsCollection as $_product) {

            $insertData = array(
                'entity_id' => $_product->getId(),
                'title' => $_product->getName(),
                'image' => $_product->getImage(),
                'url' => $_product->getUrlKey(),
                'price' => $_product->getFinalPrice(),
            );

            $this->_getWriteAdapter()->insertOnDuplicate(
                $this->getTable('atwix_sonar/suggestions'),
                $insertData,
                array('title', 'image', 'url', 'price')
            );
        }

        $currentPage++;
        //clear collection and free memory
        $productsCollection->clear();
    } while ($currentPage <= $pages);
}