Magento:在收集时设置LIMIT [英] Magento: Set LIMIT on collection

查看:105
本文介绍了Magento:在收集时设置LIMIT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出的问题是如何设置对集合的限制,我在Google上找到的答案仅适用于带有setPage($ pageNum,$ pageSize)的目录。在其他任何集合上都无效。

请参阅下面的答案。

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.

推荐答案

方法:

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

将获得前20条记录。

这里是替代方法,也许更可读的方式:

Here is the alternative and maybe more readable way:

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

这将调用Zend Db限制。您可以将偏移设为第二个参数。

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

这篇关于Magento:在收集时设置LIMIT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆