We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19889
    • 616 Posts
    that’s bad news as 0.97 is still some time away
      • 26435
      • 1,193 Posts
      Quote from: OpenGeek at Jul 14, 2007, 11:19 AM

      It’s not still being developed AFAIK, and as the 0.9.7 API will be usable as a standalone library in a similar way to this library, that is the upcoming alternative.
      Jason, could you explain to MODx PHP developers the best way to instantiate the DocumentParser so we can have an object of it in our external scripts. Some of the "asynchronous JavaScript front end/PHP backend" projects I have worked on would not work with a post back to self so I dissected MODx’s index.php and cut out the parts I needed to get my own "$modx" object in my scripts (If I remember correctly huh). I am not sure exactly what I needed, and that script probably cannibalized more of the index.php file than it needed to.

      If you have time, can you describe the most concise way, and which files need to be included (config.inc.php, protect.inc.php, document.parser.class.php) to get a fully functional DocumentParser to ->getChunk(), runSnippet(), and parse the tags in those calls?

      thanks Jason.

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


        I send pointless little messages
        • 22303 MODX Staff
        • 10,725 Posts
        In 0.9.6, a new feature was added (by netnoise) that automatically disabled the parser mode if you included index.php in your scripts so you can gain access to the $modx object with very little work.
        <?php
        include('path/to/index.php');
        
        //your code that can access $modx object
        ?>


        This works great, unless you have an auto_prepend_file configuration specified, though this is already addressed in trunk via a new constant (see FS#877). Before including the index.php file, you can simply define the constant MODX_API_MODE equal to a boolean true, i.e.
        <?php
        define('MODX_API_MODE', true);
        include('path/to/index.php');
        
        //your code that can access $modx object
        ?>


        In 0.9.6.1, the MODX_API_MODE will be the preferred method, but it is not available in 0.9.6 without patching to the latest trunk...
          • 26435
          • 1,193 Posts
          Excellent. Thanks for the clarification. My turmoils above were 0.9.5 era.

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


            I send pointless little messages
            • 26435
            • 1,193 Posts
            I am using 0.9.6.
            my script immediately halts after inclusion of index.php.

            I tried defining MODX_API_MODE as true and also set $noparser = true in my script. no matter what, statements before the inclusion are executed, everything after is not.

            Any hints or ideas?

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


              I send pointless little messages
              • 22303 MODX Staff
              • 10,725 Posts
              LOL, yeah, looks like you’ll need to take that exit() statement out of there in order to use this. Sorry, not laughing at you, but at the obvious irony of such an oversight. :’(

              NOTE: fix committed @ revision 2853 and will be merged to trunk for 0.9.6.1 release.
                • 6470
                • 69 Posts
                got problem,
                unable to run

                the following code produces
                <?php
                define('MODX_API_MODE', true);
                $path = 'd:/VertrigoServ/www/assets/modules/superFetch'.'/';
                include_once($path.'modxapi.php');
                //echo $path;
                $modx = new MODxAPI();
                
                $modx->connect();
                $modx->getSettings();
                
                $html = $modx->executeDocument(3);
                return $html;
                ?>


                « MODx Parse Error »
                MODx encountered the following error while attempting to parse the requested resource:
                « PHP Parse Error »

                PHP error debug
                Error: require_once(manager/includes/sniff/phpSniff.core.php) [function.require-once]: failed to open stream: No such file or directory
                Error type/ Nr.: Warning - 2
                File: D:\VertrigoServ\www\manager\includes\sniff\phpSniff.class.php
                Line: 22
                Line 22 source: require_once($modx->config[’base_path’] . ’manager/includes/sniff/phpSniff.core.php’);

                Parser timing
                MySQL: 0.0376 s (15 Requests)
                PHP: 0.1742 s
                  • 22176
                  • 32 Posts
                  I’ve plugged this into an SMF template.index.php page, and it’s fine when accessing a regular modx document with html only. However, when I try to link it to a chunk (specified in the content box of the doc) I get this message, instead of the output requested...

                  Could not load DBAPI class.

                  The code I am using is...

                  ’;
                  $path22 = ’C:\\XAMPP\\htdocs\\max\\’;
                  include_once($path22.’modxapi.php’);
                  $modx = new MODxAPI();
                  $html = $modx->executeDocument(42);
                  echo $html;
                  echo’

                  Can anyone give me a pointer as to where i am going wrong?

                  Many thanks, Olly.
                    www.Guvnr.com

                    .. blogging &#39;bout a way wider web

                    Currently publishing - a 20 part video series:-

                    Set Up Unmanaged VPS (4 Newbies) .. The V-P-S Bible
                    • 22176
                    • 32 Posts
                    OK, I unearthed some detail about this, at http://wiki.modxcms.com/index.php/API:DBAPI:constructor. Essentially, it says...

                    "To set your own values (for example, to connect to another database), you simply need to create a new instance of the DBAPI class."

                    ...and gives this example...

                    $mydb = new DBAPI(’host’, ’database’, ’username’, ’password’, ’table_prefix’, ’character_set’ );
                    $mydb->connect();

                    ...so I ammended my code in my SMF template page - index.template.php - to this...

                    ’;

                    $path = ’C:\\XAMPP\\htdocs\\max\\’;
                    include_once($path.’modxapi.php’);

                    $mydb = new DBAPI(’localhost’, ’modx_db’, ’modx_username’, ’modx_password’, ’modx’, ’ISO-8859-1’ );
                    $mydb->connect();

                    $modx = new MODxAPI();
                    $html = $modx->executeDocument(42);
                    echo $html;

                    echo’

                    And now I’m getting the following error...

                    Fatal error: Class ’DBAPI’ not found in C:\XAMPP\htdocs\max\forum\Sources\Load.php(1726) : eval()’d code on line 227

                    :’(

                    I’m trying to figure this out, but if anyone out there has some idea as to what this issue may be, I’d be totally, utterly, completely grateful.

                    Cheerio,

                    Olly.
                      www.Guvnr.com

                      .. blogging &#39;bout a way wider web

                      Currently publishing - a 20 part video series:-

                      Set Up Unmanaged VPS (4 Newbies) .. The V-P-S Bible
                      • 4966
                      • 143 Posts
                      First time using the api. I’m using the api with a select to find the site name from the system setting table. My code is returning Resource id #4. When I browse the database and table in phpMyAdmin I see the correct value. What am I missing? I’ve even tried just php and no api and get the same result.

                      thanks,