I'm trying to return a single GroupedList
which holds information from both pages and dataobjects
. Is there an easy way to merge the two lists together?
public function getGroupedContent()
{
$dataobjects = GroupedList::create(FileNetObject::get());
$pages = GroupedList::create($this->Children());
$result = ??;
return $result;
}
The ArrayList
merge fails as does a standard array_merge
- Would I be best merging the results from the queries together before putting it into a single GroupedList
?
Without knowing more about your situation, the simplest way to do this is:
return array_merge($dataobjects->toArray(), $pages->toArray());
To display the above in a template you would of course need to wrap that in another ArrayList.
Updated: If you want to group the lists (which of course is why you were using a GroupedList in the first place) you would need to do it before merging the arrays. More like:
return array_merge($dataobjects->GroupBy('Author')->toArray(), $page->GroupBy('Author')->toArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With