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

    I was going through the documentation but I didn’t see any where (probably missed it ...) that gives you a heads up on using xPDO in another script.
    I’m working with a cart that is MVC and a basic class for mysql but I want to recode it to run with PDO/XPDO (doctrine was thought about but ... kept coming back to xPDO grin ).

    What sort of areas should I be looking at?

    I also noticed that it has cache for memcahce and apc ... (not installed yet but was thinking of going apc and then later on in the project adding in memcache).
    Do I need this from the start?

    Since I got your attention, what is the availability of apc / memcache in the standard hosting enviornment?


    note: the project I’m working on will eventually go into the wild for others to use.


    Thanks!!

    thanks!
      Tangent-Warrior smiley
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      xPDO is just (if one can say that xPDO is "just" anything) a wrapper/extender for PDO. Actually, MODx is built using xPDO, xPDO is not built for MODx exclusively.
        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
        • 21257 MODX Staff
        • 730 Posts
        Have you checked this out, Carsten?
        http://rtfm.modx.com/display/xPDO20/Home
        Basically all you need to do to use xPDO in a script is to include xpdo.class.php, set up your connection and you’re away.
        I used it a lot this way in Evo snippets.
          Mike Schell
          Lead Developer, MODX Cloud
          Email: [email protected]
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell
          • 4673
          • 577 Posts
          Hi guys and gals!

          Actually, I started at the site then went on to the manual.
          The include part is a start ...

          I’m not using modx on the project I’m working on at the moment. However, kohana has loaded it so I’ll be looking at that part in the future.

          I’m trying to "put" xPDO in the script from scratch. And that is where the manual is lacking sad
          OR, I just missed the section completely smiley
            Tangent-Warrior smiley
            • 28215
            • 4,149 Posts
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
              • 13481
              • 97 Posts
              And by reading the docs it should get you something close to this for a start. Here is a start of an example class that I used to make a wordpress plugin (class, and variable names have been generalized to protect the innocent):

              // include xpdo
              require_once(dirname(__FILE__).'/vendor/xpdo/xpdo.class.php');
              
              class myClass extends xPDO
                {
                  private $data;
                  private $ctrl;
                  private $actn;
                  private $id;
              
                  /**
                   * Constructor (PHP 5 Only)
                   */
                  function __construct()
                  {
                    // load xpdo - the constants here come from wp-config.php
                    $dsn = 'mysql:host=localhost;dbname='.DB_NAME.';port=3306;charset=' . DB_CHARSET;
                    parent::__construct($dsn,DB_USER,DB_PASSWORD);
                   
                   $this->setDebug(MY_CONSTANT_DEBUG);
              
                   $this->setPackage('my_package_name',MY_CONSTANT_PATH.'/model/','my_databse_table_prefix_');
                   
                   ....


              In wordpress, plugins are loaded after the main wordpress config is loaded so that is where the database constants are coming from. So this is your example of including xpdo outside of MODx...it’s surprisingly similar to how it’s included in MODx.