Magento: Set LIMIT on collection


The question that I tried to find out was how do we set a Limit on a Collection, the answers that I found on Google was only available for the Catalog with a setPage($pageNum, $pageSize). That didn't work on any other collections.
See the answer below.

This question is tagged with magento collections

~ Asked on 2013-01-14 16:21:17

The Best Answer is


There are several ways to do this:

$collection = Mage::getModel('...')

Will get first 20 records.

Here is the alternative and maybe more readable way:

$collection = Mage::getModel('...')->getCollection();

This will call Zend Db limit. You can set offset as second parameter.

~ Answered on 2013-01-14 17:01:47


The way to do was looking at the code in code/core/Mage/Catalog/Model/Resource/Category/Flat/Collection.php at line 380 in Magento 1.7.2 on the function setPage($pageNum, $pageSize)

 $collection = Mage::getModel('model')
     ->setCurPage(2) // 2nd page
     ->setPageSize(10); // 10 elements per pages

I hope this will help someone.

~ Answered on 2013-01-14 16:21:17

Most Viewed Questions: