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);
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?
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.