We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9673
    • 52 Posts
    Hello, I need to get some fields of the resource through the api.
    I use modx revolution 2.1.1.
    Snippet now I have the simplest, consists only of the function

    echo $var=$modx->getDocument(50); //It must return an array


    Record with the id of course there is, it is published.
    But it does not output anything, it returns a white page.
    In the logs, such records

    92.112.28.95 - - [23/Jul/2011:15:18:59 +0400] "POST /connectors/element/propertyset.php HTTP/1.1" 200 535 "http://199.org.ua/manager/index.php?a=16&id=39" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 WebMoney Advisor"
    92.112.28.95 - - [23/Jul/2011:15:18:59 +0400] "POST /connectors/element/propertyset.php HTTP/1.1" 200 614 "http://199.org.ua/manager/index.php?a=16&id=39" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 WebMoney Advisor"

    What prevents the display array with the data resource?
      • 22303 MODX Staff
      • 10,725 Posts
      There is no method called getDocument() in MODX 2.1 — this was a legacy method from MODX Evolution that was deprecated in 2.0 and removed for 2.1. See http://rtfm.modx.com/display/revolution20/Summary+of+Legacy+Code+Removed+in+2.1.
        • 9673
        • 52 Posts
        I get an array of all parameters of the document? (title, description, content, expanded title)

        Now I did call
        $abc = $modx->getObject('modResource', 50);
        and does not show.

        I can only output through the
        echo $abc->get("pagetitle");


        for example
        $ abc array
        [title ]=>...;
        [content ]=>...;
        [destsription ]=>...;
        [crater-date ]=>...;
        etc.
          • 10487 MODX Staff
          • 1,535 Posts
          If you want an array, then you can use toArray() on the resource object:
          $abc = $modx->getObject('modResource', 50);
          $abcArray = $abc->toArray();
          echo $abcArray['pagetitle'];
          
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com