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

    //
    // Code from page 363 of MODX - The Official Guide - getObjectGraph()
    //
    // ObjectDemo is under the Home Page (1)
    //
    $output .= '<p><h2>Me and my Parent</h2></p>';
    $id = $modx->resource->get('id');
    $gresource = $modx->getObjectGraph('modResource',array('Parent' => array()), $id);
    $output .= '<p><h3>Me: ' . $gresource->get('pagetitle') . '</h3></p>';
    try {
    $pptitle = $gresource->Parent->get('pagetitle');
    } catch (Exception $e) {
    $pptitle = '';
    }
    $output .= ' - pptitle is: ' . $pptitle . '
    '; // shows ObjectDemo not Home Page.
    if ($pptitle > '') {
    $output .= ' <h3>My Parent: ' . $pptitle . '</h3>'; // shows ObjectDemo not Home Page.
    }]

    Don't understand what is wrong.
    The code: $pptitle = $gresource->Parent->get('pagetitle'); fails to get the parent pagetitle.

    Do I have something wrong here?

    Thanks,
    Bill Slaughter
      • 3749
      • 24,544 Posts
      Offhand, I don't see anything wrong with your code. The code in the book worked when I tested it, but that was a while ago. I'll try to find time to check it out.

      What version of MODX are you using?


      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 37166
        • 11 Posts
        Using version: 2.2.0-pl2.

        I like the specs!

        Thanks,
        Bill Slaughter
          • 3749
          • 24,544 Posts
          Looks like a bug in xPDO. The equivalent code still works with user/Profile, but I get the same thing you do with resource/Parent. I've filed it as a bug.


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            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
            • 37166
            • 11 Posts
            Thanks, Bob.