Generate Doctrine models/classes that extend a custom record class

When using using Doc­trine 1.2.1 and Zend Frame­work 1.9.x to gen­er­ate classes from Yaml/db each Base class (which includes the table def­i­n­i­tion) extends the Doctrine_Record class.

I need to find a way of telling Doc­trine to extend my own Base class, or find a dif­fer­ent solu­tion to a master/slave db setup using Doctrine.

Exam­ple gen­er­ated model:

abstract class My_Base_User extends Doctrine_Record
{

How­ever I need it to be auto­mat­i­cally gen­er­ated as:

abstract class My_Base_User extends My_Record
{

And the answer is (drumroll)

Typ­i­cal, as soon as I ask the ques­tion I man­age to find the answer. I’m record­ing it here in case any­one else has the same issue.

You can pass in the para­me­ter ‘base­Class­Name’ into the gen­er­ate­Mod­els* meth­ods and Doc­trine will use that as the Base record class.

Exam­ples:

Doctrine_Core::generateModelsFromDb('models', array('master'), array('generateTableClasses' => true, 'baseClassName' => 'My_Record'));

or using Cli:

$options['generate_models_options'] = array(
'pearStyle'             => true,
'baseClassPrefix'       => 'My_',
'baseClassName'         => 'My_Record',
'classPrefix'           => '',
'classPrefixFiles'      => false,
'generateTableClasses'  => true,
);
$cli = new Doctrine_Cli($options);

Tags: ,

4 Responses to "Generate Doctrine models/classes that extend a custom record class"

Leave a Comment

*

Get Adobe Flash player