I have an object:
$modParentGroup = $modx->getCollection('modUserGroup',array('parent'=>$groupID));
where $groupID is the ID of the parent of the resource I am interested in.
which I wish to sort via the
description field of modUserGroup. I tried using
$modParentGroup->sortBy('description','ASC');
which did not work. The error I get is
Fatal error: Call to a member function sortBy() on a non-object in...
I also tried a usort which did not work as $modParentGroup is not an array.
Very confused.
Many thanks in advance.
Glyn Szasz
Sydney, Australia
Happy to help (when can) and happy to learn
If you are a Sydney based MODX developer would love to hear from you. Please contact me.
try:
$c = $modx->newQuery('modUserGroup');
$c->where(array('parent'=>$groupID));
$c->sortBy('description','ASC');
if ($collection = $modx->getCollection('modUserGroup',$c)){
foreach ($collection as $object){
$row = $object->toArray();
$rows[] = $row;
}
echo '<pre>' . print_r($rows,1) . '</pre>' ;
}
Thank you so much Bruno. It worked.
When you visit Sydney, I owe you a beer.
Glyn Szasz
Sydney, Australia
Happy to help (when can) and happy to learn
If you are a Sydney based MODX developer would love to hear from you. Please contact me.