Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Set current, then find next on a DataObjectSet


Go to End


2 Posts   2347 Views

Avatar
gcoderre

Community Member, 5 Posts

12 April 2011 at 3:40am

I'm not sure I'm tackling this problem from the right angle, but here's my situation:

On a page that displays a single DataObject, I want to be able to link to the next / previous DataObject in a DataObjectSet.

I know one can peek the previous / next item in a DataObjectSet_Iterator, but is there a way to set the Iterator's current position to a specific item?

$current_photo = $this->getPhoto(); // DataObject of the current photo
$photos = $this->Photos(); // DataObjectSet
$iterator = $photos->getIterator(); // DataObjectSet_Iterator

$iterator->peekNext(); // DataObject
$iterator->peekPrev(); // DataObject

Thanks much for your help

Avatar
swaiba

Forum Moderator, 1899 Posts

18 April 2011 at 7:05am

you might use ->toArray() instead...

alternatively set the pagesize to 1 and then use pagination (http://www.sspaste.com/paste/show/4d3ff85db4346)