7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Problem Sorting For Display
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 333 Views |
-
Problem Sorting For Display

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?
-
Re: Problem Sorting For Display

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"
);
} -
Re: Problem Sorting For Display

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
-
Re: Problem Sorting For Display

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.
| 333 Views | ||
|
Page:
1
|
Go to Top |


