We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37523
    • 141 Posts
    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.
      • 4172
      • 5,888 Posts
      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>' ;
      
      }
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37523
        • 141 Posts
        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.