1

I would like to access any element of a magento collection by its "index". i know that i can sort magento collections and filter them by calling $collection->addFieldToFilter() and $collection->setOrder() so if I set the order and I know how many elements I have is there a way to access the elements randomly? I would assume the functionality exists given that there are methods for getFirstItem and getLastItem.

The context of my problem is that i would like to be able to access up to ten elements back into a history of entries that are saved to the database, think command line with up and down arrow keys

4

1 回答 1

0

它不能在一行中完成,您可以获取内部_items数组 Magento users 以将单个对象存储在集合中

$items = $collection->getItems();

从那里开始,$items就是一个简单的 PHP 数组——随心所欲地随机访问。

于 2013-07-03T01:02:07.057 回答