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

    Im a new user of modx.

    Now, i learn xPDO.

    So, i tried to use simple methods getObject in snippet. That's ok.

    Then I created php
    <?php
    print_r('start prototype');
    $obj = $modx->getObject('modResource', 1); 
    print $obj->pagetitle; 
    


    in root directory MODx and got this error:
    Fatal error: Call to a member function getObject() on a non-object in Z:\home\wh.bz\www\assets\pro.php on line 3

    Why?

    Please help me!
      • 3749
      • 24,544 Posts
      Are you running this outside of MODX? If so, you need to load and initialize modx before you can use it.

      something like this:

      <?php
      // adjust this as necessary
      $path = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/config/config.inc.php';
      if (file_exists($path)) {
         include($path);
      } else {
         die ('Could not find config.inc.php at ' . $path;
      }
      require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
      $modx = new modX();
      /* Initialize and set up logging */
      $modx->initialize('mgr');  // or $modx->initialize('web');
      $modx->getService('error', 'error.modError', '', '');
      $modx->setLogLevel(xPDO::LOG_LEVEL_INFO);
      $modx->setLogTarget(XPDO_CLI_MODE
          ? 'ECHO'
          : '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
        • 44298
        • 8 Posts
        Thank you!