We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Just to clear on what xPDO is doing... if I’ve got an XML file all worked out, I know I can use xPDO to slurp that schema up and generate a database table, but does it also generate a PHP class with code somewhere? Where are these Model files stored?

    My point of comparison here is CakePHP, which would generate class files. Is this in fact what xPDO does when you first run a build script?

    Thanks for clarifying.
    • Check out http://api.modxcms.com/
      Go to xpdo > om > Classes > xPDOGenerator
      and look at the parseSchema method.

      Below is the code I use to generate (and update) classes and maps after I create/refine the model xml. Note the sys.inc file is just my own convention and is where the various CONSTs come from. You don’t have to use those names of course.

      <?php
      include dirname(dirname(__FILE__)) . '/inc/sys.inc';
      include_once XPDO_PATH . '/xpdo.class.php';
      
      $xpdo= new xPDO(XPDO_DSN,XPDO_DBUSER,XPDO_DBPW);
      
      // Set the package name and root path of that package
      $xpdo->setPackage(XPDO_PACKAGE, XPDO_OM_PATH);
      
      $xpdo->setDebug(XPDO_SET_DEBUG);
      
      $manager= $xpdo->getManager();
      $generator= $manager->getGenerator();
      
      //Use this to create a schema from an existing database
      //$xml= $generator->writeSchema(XPDO_SCHEMA_PATH . '/new.' . XPDO_PACKAGE . '.mysql.schema.xml', XPDO_PACKAGE, 'xPDOObject');
      
      //Use this to generate classes and maps from your schema
      // NOTE: by default, only maps are overwritten; delete class files if you want to regenerate classes
      $generator->parseSchema(XPDO_SCHEMA_PATH . '/' . XPDO_PACKAGE . '.mysql.schema.xml', XPDO_OM_PATH);
      

        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
      • Sorry, I’m still confused. Does this generate actual .php files on the file system, or do I need to do something like you’ve outlined each time I access my model?
          • 28215
          • 4,149 Posts
          splittingred Reply #4, 14 years ago
          Quote from: Everett at Apr 28, 2010, 12:47 AM

          Just to clear on what xPDO is doing... if I’ve got an XML file all worked out, I know I can use xPDO to slurp that schema up and generate a database table, but does it also generate a PHP class with code somewhere? Where are these Model files stored?
          My point of comparison here is CakePHP, which would generate class files. Is this in fact what xPDO does when you first run a build script?
          Thanks for clarifying.

          Yes, xPDO has class and db map files that are generated when you build from an XML schema (as netProphet has outlined). You then add those maps/classes to an xPDO instance via $xpdo->addPackage.

          Everett, have you read the xPDO Docs?

          Specifically, this page: http://svn.modxcms.com/docs/display/xPDO20/Creating+a+Model+With+xPDO
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • Thanks for the links. Yes, I’ve read a lot of the docs, but there’s plenty of room for misunderstandings in there. I’m making clarifications as I go in the hopes that the instructions will be clearer for the next people.