Jump to:

3373 Posts in 998 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » ArrayList Sort not working

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

Page: 1
Go to End
Author Topic: 317 Views
  • davidglassford
    Avatar
    Community Member
    1 Post

    ArrayList Sort not working Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: ArrayList Sort not working Link to this post

    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');

    317 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.