Jump to main content Jump to doc navigation

xPDOGenerator::writeSchema

Parses an existing database and generates a XPDO XML schema from it.

Syntax

API Docs: http://api.modxcms.com/xpdo/om-mysql/xPDOGenerator_mysql.html#writeSchema

boolean writeSchema (
  string $schemaFile,
  [string $package = ''],
  [string $baseClass = ''],
  [string $tablePrefix = ''],
  [boolean $restrictPrefix = false])

Example

Generate the xml schema from an existing database. This also only generates XML for the tables prefixed with 'mydb_'.

$xpdo= new xPDO('mysql:host=localhost;dbname=myolddatabase','username','password','mydb_');
$manager= $xpdo->getManager();
$generator= $manager->getGenerator();

$xml= $generator->writeSchema('/path/to/my/new/packagename.schema.xml','mypackage', 'xPDOObject','mydb_');

Note: generating the XML schema doesn't generate the aggregate and composite relationships - just the field and object definitions. You'll need to specify those relationships yourself. See Defining Relationships for more details.

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • eydolan
  • Lefthandmedia
  • Murray Wood
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$306 per month—let's make that $500!

Learn more