We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51048
    • 14 Posts
    Hi,

    I'm trying to list all resources and I need to display the field names as well.

    I use this code

    $c = $modx->newQuery('modResource');
    $c->where(array('id' => $id));
    $data = $modx->getCollection('modResource',$c);
    
    foreach ($data as $key => $value) {
        error_log("Key: ".$key . "Value: ".$value);
    }	
    


    currently, it gets the field values only in key place and the value is empty.

    How can I get the field name as well?

    Thanks

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      $c = $modx->newQuery('modResource');
      $c->where(array('id' => $id));
      $collection = $modx->getCollection('modResource',$c);
      foreach ($collection as $resource){ 
          $data = $resource->toArray();
          foreach ($data as $key => $value) {
              error_log("Key: ".$key . "Value: ".$value);
          }   
      }
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 51048
        • 14 Posts
        Quote from: Bruno17 at Oct 08, 2015, 08:54 AM
        $c = $modx->newQuery('modResource');
        $c->where(array('id' => $id));
        $collection = $modx->getCollection('modResource',$c);
        foreach ($collection as $resource){ 
            $data = $resource->toArray();
            foreach ($data as $key => $value) {
                error_log("Key: ".$key . "Value: ".$value);
            }   
        }

        Hey Bruno, works great, thanks smiley