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?
We've moved the forum!
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
DataObjectManager Module /
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba
Problem Sorting For Display
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"
);
}
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
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.