Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Problem Sorting For Display

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 657 Views
  • smaction
    Avatar
    Community Member
    4 Posts

    Problem Sorting For Display Link to this post

    I hope I have identified the correct module. Here is my question. My Photos are looped through here http://pastebin.com/gnL5f51n. The issue can best be explained by looking at these two images. The first shows the order they are in the database after they are entered. Screen shot is here: http://imgur.com/gukAHxJ However, when they are sorted by PageID (which I assume is how they are looped through) they are not in entry order. Screen shot here :http://imgur.com/43Ajuik How can I change the order that Photos are looped?

  • frankmullenger
    Avatar
    Forum Moderator
    51 Posts

    Re: Problem Sorting For Display Link to this post

    You could try setting the $default_sort on your Photo DataObject..

    static $default_sort = "Date ASC";

    Or even overriding the way Photos are retrieved from your Page..

    public function Photos() {
    return $this->getManyManyComponents( //Or HasMany depending...
    'Photos',
    '',
    "\"Photos\".\"Date\" ASC"
    );
    }

  • smaction
    Avatar
    Community Member
    4 Posts

    Re: Problem Sorting For Display Link to this post

    Thanks. I am still a little confused (I guess I do not understand Silverstripe as well as I thought).

    I cannot find a variable or function anywhere in my website source that has a function or variable Photos.

    I have a Photo.php page with the following in it:

    <?php

    class Photo extends DataObject{

    static $db = array(
          'Name' => 'Text',
    );
    static $has_one = array(
          'Attachment' => 'Image',
          'Page' => 'Page'
    );

    public function getCMSFields_forPopup(){
          return new FieldSet(
                new TextField('Name'),
                new FileIFrameField('Attachment')
          );
    }

    }

    Is this where you are suggesting I make the change you wrote?

    Scott

  • frankmullenger
    Avatar
    Forum Moderator
    51 Posts

    Re: Problem Sorting For Display Link to this post

    In the Photo class you can specify the $default_sort - that should do what you want it to.

    In your Page class you probably have a $has_many => Photos, because function Photos() is not declared the __call() magic method is used instead, which in a roundabout way will call getComponents or getManyManyComponents iirc. If you do declare function Photos() in your Page class that will be used instead of resorting to __call() basically.

    657 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.