We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31053
    • 31 Posts
    Hello. I have MODx Revolution 2.0.8-pl on Apache.
    Everything works fine except modx api.
    I have php file (http://eltex-msk.ru/_test.php) with code:

    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';
    $modx = new modX();
    $modx->setLogLevel(modX::LOG_LEVEL_DEBUG);
    $modx->log(modX::LOG_LEVEL_DEBUG, 'API START'); 
    $modx->initialize('web'); 
    
    $prodTemplate = $modx->getObject('modTemplate',1);
    if(!is_null($prodTemplate)) echo 'ok'; 
    


    It works fine. But, if I loged in as admin, on this page I get HTTP 502 (Bad Gateway).
    WTF? o_O

    In logs only one string:
    [2011-04-23 02:24:13] (DEBUG @ /_test.php) API START


    Help me please!
      for($i=0; $i<100; $i++) echo &#39;Why is it not working?&#39;;
      • 3749
      • 24,544 Posts
      The code you’re using is only for running scripts outside of MODX. Since you’re inside MODX when logged in, it doesn’t work (and isn’t necessary). You definitely don’t want to be using $modx = new modX(); when you’re already *inside* MODX. wink

      If it’s in a snippet, all you need are these two lines:

      $prodTemplate = $modx->getObject('modTemplate',1);
      if(!is_null($prodTemplate)) echo 'ok'; 
      
        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
        • 31053
        • 31 Posts
        _test.php - this is an external php file. And it is used for AJAX requests. So what do you suggest does not work of course.
          for($i=0; $i<100; $i++) echo &#39;Why is it not working?&#39;;
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: unglued at Apr 24, 2011, 07:54 AM

          _test.php - this is an external php file. And it is used for AJAX requests. So what do you suggest does not work of course.
          Why are you creating external PHP files for AJAX requests? These work fine as Resources with Snippets, and I recommend not creating new gateways into MODX. This can create attack vectors if you do not take care of the the things the MODX core request handlers already do for you.