Doctrine 1.2 has a method called generateModelFromDb, documented here, that generates model files for all of the tables in a database.
This function accepts an optional third parameter with an array of "options" to use when generating models, the specifics of which are not documented. What options are available for me to specify here?
The complete list with default values from Doctrine/Import/Schema:
protected $_options = array('packagesPrefix' => 'Package',
'packagesPath' => '',
'packagesFolderName' => 'packages',
'suffix' => '.php',
'generateBaseClasses' => true,
'generateTableClasses' => false,
'generateAccessors' => false,
'baseClassPrefix' => 'Base',
'baseClassesDirectory' => 'generated',
'baseClassName' => 'Doctrine_Record');
Using Doctrine1.2.4 -
There are a few missing from that list - and they are important ones!
'pearStyle' => true,
'classPrefix' => '',
'classPrefixFiles' => false,
I used this when generating my classes for a Zend Framework project, example script:
<?php
/**
* Doctrine CLI script
*/
define('APPLICATION_ENV', 'development');
define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/../library/Doctrine'),
get_include_path(),
)));
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/config/default.ini'
);
$application->getBootstrap()->bootstrap('doctrine');
Doctrine::generateModelsFromDb(
APPLICATION_PATH . '/modules/default/models/DbTable',
array('db1'),
array(
'pearStyle' => true,
'generateTableClasses' => true,
'baseClassesDirectory' => '',
'classPrefix'=> 'Model_DbTable_',
'classPrefixFiles' => false,
'baseClassPrefix' => 'Generated_'
)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With