Jump to:

3373 Posts in 999 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Set current, then find next on a DataObjectSet

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

Page: 1
Go to End
Author Topic: 1474 Views
  • GuillaumeC
    Avatar
    Community Member
    5 Posts

    Set current, then find next on a DataObjectSet Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Set current, then find next on a DataObjectSet Link to this post

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

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

    1474 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.