Silverstripe merge GroupedLists

I am trying to return one GroupedList that contains information from both pages and dataobjects . Is there an easy way to combine two lists together?

 public function getGroupedContent() { $dataobjects = GroupedList::create(FileNetObject::get()); $pages = GroupedList::create($this->Children()); $result = ??; return $result; } 

The ArrayList merge fails, as array_merge standard array_merge . Would it be better to merge the results from the queries together before putting them into one GroupedList ?

+5
source share
1 answer

Without knowing more about your situation, the easiest way to do this is:

 return array_merge($dataobjects->toArray(), $pages->toArray()); 

To display above in the template, you, of course, will need to wrap this in another ArrayList.

Updated: if you want to group lists (this, of course, is why you used GroupedList in the first place), you will need to do this before merging the arrays. More like:

 return array_merge($dataobjects->GroupBy('Author')->toArray(), $page->GroupBy('Author')->toArray()); 
+1
source

All Articles