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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Problem Sorting For Display


4 Posts   666 Views


31 January 2013 at 8:00am Community Member, 4 Posts

I hope I have identified the correct module. Here is my question. My Photos are looped through here 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: 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 : How can I change the order that Photos are looped?


31 January 2013 at 11:38am Forum Moderator, 51 Posts

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\".\"Date\" ASC"


31 January 2013 at 11:49am Community Member, 4 Posts

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:


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?



31 January 2013 at 12:13pm Forum Moderator, 51 Posts

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.