What are the options available for Doctrine's Doctrine_Core::generateModelsFromDb method?
Doctrine 1.2 has a method called generateModelFromDb, documented here, that generates model files for all of the tables in a database.
This function ac开发者_JAVA技巧cepts 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_'
)
);
The best I've seen is this:
http://www.doctrine-project.org/documentation/manual/1_2/ru/defining-models
... where you can try glean off the page any data type-specific "options". I haven't come across anything more comprehensive than that. The API documentation seems to assume that it's obvious what the possible options are.
This looks promicing: from here
// Generate your models from an existing database
Doctrine::generateModelsFromDb('/path/to/generate/models', array('connection_name'), $options);
// Array of options and the default values
$options = array('packagesPrefix' => 'Package',
'packagesPath' => '',
'packagesFolderName' => 'packages',
'suffix' => '.php',
'generateBaseClasses' => true,
'baseClassesPrefix' => 'Base',
'baseClassesDirectory' => 'generated',
'baseClassName' => 'Doctrine_Record');
精彩评论