We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22549
    • 19 Posts
    i was wondering how to make an ajax call, I’ve made a snippet with this code

    jsInclude = "<script>
    var pars = 'q=assets/snippets/MaxiGallerySlideShow/MaxiGallerySlideShow.php';
    	new Ajax.PeriodicalUpdater('something', 'index-ajax.php', {asynchronous:true, frequency:5, postBody: pars});
    </script>";
    $modx->regClientScript($jsInclude);
    


    My question is, can I use $modx-> functions in my php page, I want to use a few DB connections...

    Thanks in advance
      • 22549
      • 19 Posts
      Quote from: pachirulo at May 15, 2007, 02:23 PM

      i was wondering how to make an ajax call, I’ve made a snippet with this code

      jsInclude = "<script>
      var pars = 'q=assets/snippets/MaxiGallerySlideShow/MaxiGallerySlideShow.php';
      	new Ajax.PeriodicalUpdater('something', 'index-ajax.php', {asynchronous:true, frequency:5, postBody: pars});
      </script>";
      $modx->regClientScript($jsInclude);
      


      My question is, can I use $modx-> functions in my php page, I want to use a few DB connections...

      Thanks in advance

      I really have to understand how I can make DB calls in my php page using $modx API, does anyone knows how to do this?
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You need to have your code include() the manager/includes/config.inc.php file, at the least. You can include the manager/includes/document_parser.class.inc.php file too, if you want to use the modx class functions.
          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
          • 22549
          • 19 Posts
          Quote from: sottwell at May 16, 2007, 08:48 AM

          You need to have your code include() the manager/includes/config.inc.php file, at the least. You can include the manager/includes/document_parser.class.inc.php file too, if you want to use the modx class functions.

          take a look to mi PHP page, this code is called by index-ajax.php, and is located into assets/snippets/slideshow/slideshow.php

          I can’t make a simple echo :S
          include ('manager/includes/config.inc.php');
          include ('manager/includes/document_parser.class.inc.php');
          
          $table = $modx->getFullTableName("maxigallery");
          
          echo $table; //THIS ECHO DOESNT DISPLAY ANYTHING
          
          $pictures = $modx->db->select("title, filename, gal_id, id", $table);
          
          for($i=0;$i<@$modx->recordCount($pictures) ;$i++)
          {
          	   array_push($picturesArray,@$modx->fetchRow($picture));
          }
          
          echo sizeof($picturesArray); //ALSO THIS ECHO
          
            • 22549
            • 19 Posts
            Susan, You told me to include config.inc.php and document_parser...
            I take a look to index-ajax.php, and notify that config.inc.php is already included, so I don’t need ir anymore in my php page... what I need is to use modx object.

              • 28042 ☆ A M B ☆
              • 24,524 Posts
              The only way to get the $modx object is to include the parser and instantiate a new $modx object, just like the main index.php file does.
                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
                • 22549
                • 19 Posts
                Quote from: sottwell at May 17, 2007, 01:30 AM

                The only way to get the $modx object is to include the parser and instantiate a new $modx object, just like the main index.php file does.

                And whats the optimal code I can use, instantiate new modx object in memory and performance, is usefull?
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I’ve done it when using Ajax, and I’ve also just loaded up the config.inc.php file and used the basic PHP mysql calls. I couldn’t notice any difference, but then I’ve yet do this on any busy sites.
                    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