We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8684
    • 29 Posts
    Hi, I want to do that because I’m using ajax request.
    See, in my snippet i have a button that calls a javascript function which is in fact my "ajax" function but this function referes to another php file, the one that will return what i want in the div I want.
    But in this file I can’t use for instance
    $modx->getFullTableName('web_users');


    and i’m forced to write a mysql query to retreive the info I want.

    I tried to include the parser class file and to declare $modx global variable in my ajax php file but still display this error message:
    Fatal error: Call to a member function getFullTableName() on a non-object in


    does anyone have an idea how to use the parser outside modx?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You have to include the /manager/includes/config.inc.php file, then the /manager/includes/document.parser.class.inc.php file, then create a new instance of the parser class. See the index.php file for how it it done there.
      // initialize the variables prior to grabbing the config file
      $database_type = '';
      $database_server = '';
      $database_user = '';
      $database_password = '';
      $dbase = '';
      $table_prefix = '';
      $base_url = '';
      $base_path = '';
      
      // get the required includes
      if($database_user=="") {
      	$rt = @include_once(dirname(__FILE__).'/manager/includes/config.inc.php');
      ...
      // initiate a new document parser
      include_once(MODX_MANAGER_PATH.'/includes/document.parser.class.inc.php');
      $modx = new DocumentParser;
      

      Of course, you’ll need to make sure the path to the config.inc.php file is correct relative to your external .php file.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 26435
        • 1,193 Posts
        Quote from: sottwell at Sep 08, 2007, 12:02 AM

        You have to include the /manager/includes/config.inc.php file, then the /manager/includes/document.parser.class.inc.php file, then create a new instance of the parser class. See the index.php file for how it it done there...
        Even better yet!
        If you are running MODx 0.9.6, just include index.php!
        See this thread: http://modxcms.com/forums/index.php/topic,6154.msg106656.html#msg106656
        and read the next 4 posts or so after it because there is an exit() statement in index.php that needs to be removed. This has been fixed in 0.9.6.1, but for now you have to take it out of index.php.

        -sD-
        Dr. Scotty Delicious, Scientist DFPA.
          Husband, Father, Brother, Son, Programmer, Atheist, Nurse, Friend, Lover, Fighter.
          All of the above... in no specific order.


          I send pointless little messages
          • 8684
          • 29 Posts
          thanks! I tried both solution, but didn’t succeed in getting the one with index.php to work.