开发者

Magento resource model filter and limit

Hi when getting a resource model in magent using 开发者_如何转开发Mage::getResourceModel i can add filters no problem but how can i limit the result set to say 5 or 10?


Assuming you're talking about Magento Collections, the ORM uses a paging style interface to limit things. You tell the collection how big you want each page to be (setPageSize), then you tell it which page you want to be on (setCurPage).

//same as, and "better" than Mage:getResourceModel('catalog/product_collection');
Mage::getModel('catalog/product')
->getCollection()
->setPageSize(10)->setCurPage(1);     //first 10 items


Mage::getModel('catalog/product')
->getCollection()
->setPageSize(10)->setCurPage(2);     //second 10 items

///etc...


$select->limit(5)  

check for example the _getProducts() method in app/core/mage/Catalog/Model/Resource/Eav/Mysql4/Url.php (line 806)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜