Magento: Set LIMIT on collection

后端 未结 4 1460
甜味超标
甜味超标 2021-02-01 01:58

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, $

4条回答
  •  太阳男子
    2021-02-01 02:45

    There are several ways to do this:

    $collection = Mage::getModel('...')
                ->getCollection()
                ->setPageSize(20)
                ->setCurPage(1);
    

    Will get first 20 records.

    Here is the alternative and maybe more readable way:

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

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

提交回复
热议问题