Jump to:

23478 Posts in 18950 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Pagination questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 1035 Views
  • Dave L
    Community Member
    56 Posts

    Pagination questions Link to this post

    So far I'm tracking the "current" item in a paginated DataObjectSet manually, I'm wondering if there's a better way to do this. I.e. access the iterator for a DataObjectSet attached to a Page.


    simple gallery:

    Page with has_many Images

    page 1
    - image 1
    - image 2
    - image 3
    - image 4

    page 2
    - image 5
    - image 6
    - image 7
    - image 8

    page 3
    - image 9
    - image 10
    - image 11
    - image 12

    Each page shows the "current" image, plus paginated thumbnails. Each thumbnail updates "current" to the selected thumbnail. I.e. page/showImage/7

    I can paginate fine, showing thumbnails, using the standard pagination examples. To ensure the current page is not reset when I click the thumbnail on page 2 or 3 I need to pass the start (paginator) param, generated from my controller. I.e. page/showImage/7?start=5


    function CurrentPageLink() {
    if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
    return $_GET['start'];



    To keep track of "current" I have a variable in my controller, which updates the ID when a new ID is passed in, then gets the object via DataObject::get(). Is there a better way to do this? Ideally I'd like iterator access "built-in". I.e. to get the "current" Image:


    function CurrentImage() {
    return $this->Images()->Current();

    instead of:


    function CurrentImage() {
    if($this->currentImage) {
    return $this->currentImage;
    } else {
    $this->currentImage = DataObject::get_one("Image", "GalleryPageID = $this->ID"); //get first image attached to page
    return $this->currentImage;

    Am I missing something here? The reason I ask, is that accessing iteration via the DataObjectSet opens up Next(), Prev(), etc. objects. If I try to access $this->Images()->Current() I simply get [User Error] Uncaught Exception: Object->__call(): the method 'current' does not exist on 'ComponentSet'. Even though ComponentSet is a subclass of DataObjectSet, which has a current() method, it's not available. Because it does not have an iterator attached? If someone could help explain it'd be great.


  • Dave L
    Community Member
    56 Posts

    Re: Pagination questions Link to this post


    how can I paginate a set 4 at a time yet also paginate individual items?

    << item 7 >>

    << item 5, item 6, item 7, item 8 >>

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.