简体   繁体   English

Magento资源模型过滤器和限制

[英]Magento resource model filter and limit

嗨,当使用Mage :: getResourceModel在magent中获取资源模型时,我可以添加过滤器没有问题,但是如何将结果集限制为5或10?

Assuming you're talking about Magento Collections, the ORM uses a paging style interface to limit things. 假设您在谈论Magento集合,那么ORM使用分页样式界面来限制事物。 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 ). 您告诉集合您希望每个页面多大( setPageSize ),然后告诉它要放在哪个页面上( 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)  

检查app/core/mage/Catalog/Model/Resource/Eav/Mysql4/Url.php_getProducts()方法(第806行)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM