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?
A:
$select->limit(5)
check for example the _getProducts() method in app/core/mage/Catalog/Model/Resource/Eav/Mysql4/Url.php (line 806)
david parloir
2010-08-20 13:50:00
no that doesnt work when using it with mage::getResourceModel
David
2010-08-20 15:53:04
+1
A:
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)->setPage(1); //first 10 items
Mage::getModel('catalog/product')
->getCollection()
->setPageSize(10)->setPage(2); //second 10 items
///etc...
Alan Storm
2010-08-20 16:20:58