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

    I’ve discovered that the $modx->error->failure() function doesn’t work when I load modx externally. Here is my code:

    <?php
    // Load the config.core.php and the load the configuration and MODx itself
    require_once './config.core.php';
    require_once MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php';
    require_once MODX_CORE_PATH.'model/modx/modx.class.php';
    
    // Initialize MODx in the web contect
    $modx = new modX();
    $modx->initialize('web');
    
    die($modx->toJSON($modx->error->failure('Error!')));


    produces

    Fatal error: Call to a member function failure() on a non-object in /Users/Josef/Documents/Entwicklung/MAMP/GalleryGear/test.php on line 11

    It works though when I call it in a custom manager page. I use Revo 2.0.8-pl (traditional). If you want to reproduce what I did simply put the php script above into a file and store it in the main directory.

    thanks for help

    PS: The new site design is just awsome laugh
      • 28215
      • 4,149 Posts
      You need to load the error handler:

      $modx->request->loadErrorHandler();
      
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 13735
        • 62 Posts
        Thanks! I inserted it after the context initialization. But now I’ve got this..

        Fatal error: Call to a member function loadErrorHandler() on a non-object in /Users/Josef/Documents/Entwicklung/MAMP/GalleryGear/test.php on line 10
          • 28215
          • 4,149 Posts
          Hrm. You’re not handling a request, I guess, so do this instead:

          $modx->getService('error','error.modError');
          


          That’ll load the error handling class as a service. That should work; just tested it.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 13735
            • 62 Posts
            It works! Thanks!