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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Problem Sorting For Display


Go to End


4 Posts   1223 Views

Avatar
smaction

Community Member, 4 Posts

31 January 2013 at 8:00am

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?

Avatar
frankmullenger

Forum Moderator, 53 Posts

31 January 2013 at 11:38am

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"
  );
}

Avatar
smaction

Community Member, 4 Posts

31 January 2013 at 11:49am

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

Avatar
frankmullenger

Forum Moderator, 53 Posts

31 January 2013 at 12:13pm

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.