Doctrine Generate Models from DB

Automatically generating the models for a project based off of existing database tables is extremely handy. I’ve had to do this several times and the available options are key, especially when generating these for a Zend Framework layout. The following stack overflow entry is very helpful:

http://stackoverflow.com/questions/2605291/what-are-the-options-available-for-doctrines-doctrine-coregeneratemodelsfromd/6541608#6541608

/**
* 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_'
)
);

Tuesday, November 15th, 2011 Doctrine, Zend Framework

Leave a Reply

You must be logged in to post a comment.

[ad code=1 align=center]