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.

Data Model Questions /

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

ArrayList Sort not working


Go to End
Reply


2 Posts   1184 Views

Avatar
davidglassford

Community Member, 1 Post

30 October 2013 at 2:15am

Hey all,

I'm new to silverstripe and trying to combine two dataobjects into an ArrayList and then sort it by Date/Created but It doesn't do the sort. I've included the code below.

$displayContent = ArrayList::create();

$projectPages = ProjectPage::get()->sort('Created', 'DESC');
$blogPages = BlogEntry::get()->sort('Created');

foreach ($projectPages as $projectPage) {
$displayContent->merge($projectPage);
}
foreach ($blogPages as $blogPage) {
$displayContent->merge($blogPage);
}

$displayContent->sort('Created');

return $displayContent;

Thanks for any help

David

Avatar
Willr

Forum Moderator, 5517 Posts

30 October 2013 at 7:02pm

Lists are mostly immutable (i.e operations on lists give you back new lists) so when you do your sort you need to get your list

$sorted = $list->sort('Created');