We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    What am I doing wrong here:

    $resources = $modx->getCollectionGraph('modDocument', array('Children' => array()), array('published' => '1'));
    
    // $resources = $modx->getCollectionGraph('modDocument', '{"Children":{}', array('published' => '1')); // same result
    
    
    foreach($resources as $resource) {
        var_dump($resource->toArray());
        var_dump($resource->Children->toArray());
    }


    The same code works with users or using getObjectGraph() but this chokes:
    Fatal Error: cannot redeclare quote_meta()
    .
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 22295
      • 153 Posts
      Your getCollectionGraph() is perfectly ok and working.
      Your problem is actually with the var_dump:
      Modx IS parsing the returned pages and gives you back this "cannot redeclare quote_meta()" - you shouldn’t care about this. just go on with your real parsing.

      for testing: replace your var_dump with print_r and the "problem" will disappear.
      oh, and add an ’if !empty’ to the second case:
      if (!empty($resource->Children)) print_r($resource->Children->toArray());
        • 3749
        • 24,544 Posts
        Duh. Docs with no children.

        Still, not quite right, though.

        On the first document that has children, it fails, telling me that $resource->Children is not an object.

        If I do print_r($resource->Children), (rather than Children->toArray()) I get a monstrous dump of everything from soup to nuts, but no errors.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 3749
          • 24,544 Posts
          Duh again. $resource->Children isn’t an object (unlike $user->Profile). It’s an array of objects.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 22295
            • 153 Posts

            On the first document that has children, it fails, telling me that $resource->Children is not an object.
            Duh again. $resource->Children isn’t an object (unlike $user->Profile). It’s an array of objects.

            Yes. getMany vs. getOne
            In your case you use the xGraph methods, so you’ll have to know what you expect.
            although it’s the same, sometimes it’s better to use the getMany/getOne and not the xGraph methods - then you know for sure what to expect. You can also take a look at \core\model\schema\modx.mysql.schema.xml to see how the relationships are defined.

            btw, take a look at this tip: http://modxcms.com/forums/index.php?topic=44049.0

            If I do print_r($resource->Children), (rather than Children->toArray()) I get a monstrous dump of everything from soup to nuts, but no errors.

            Sure.. depanding on your php settings you can even just get an endlessly long loading page...
            just use the ->toArray() or a ->get() specific field - anyway it’s temporary, you do this print_r only for tracing/debugging.
              • 3749
              • 24,544 Posts
              Quote from: oori at Mar 30, 2010, 07:06 AM


              btw, take a look at this tip: http://modxcms.com/forums/index.php?topic=44049.0

              Good tip. Thanks. smiley
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting