开发者

Does Doctrine 2.0 pre-generate model classes like Propel 1.5 does?

开发者 https://www.devze.com 2023-03-05 09:19 出处:网络
Propel can generate classes based on a schema file. Some of the resulting classes are: The object (e.g. User)

Propel can generate classes based on a schema file. Some of the resulting classes are:

  • The object (e.g. User)
  • The Peer (e.g. UserPeer)
  • The Query (e.g. UserQuery)

The object class (User) includes getters and setters for all of the attributes. E.g.

$user = new User();
echo $user->getEmailAddress();
开发者_Python百科

My question is: can Doctrine 2.0 do this? Does it generate base classes and does it add getters and setters?


Yes Doctrine 2 does support schema to class generation, I prefer YAML over XML so here's the link covering that http://www.doctrine-project.org/docs/orm/2.0/en/reference/yaml-mapping.html

AND then via the Doctrine command line tools, you can take the provided YML files and generate http://www.doctrine-project.org/docs/orm/2.0/en/reference/tools.html

As for your second question, for the most part Doctrine does have simple setters/getters but they're called accessor methods in Doctrine terminology.

Update:

For completely generated classes, give a table like

user:
   id: integer   
   name: string
   active: bool

it would be $user->getName() and $user->setName("Joe"), $user->setActive(true) and $user->getActive();

How it generates these intermediate classes can be somewhat understood by checking out this file in the Doctrine 2 git repo https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/EntityGenerator.php

0

精彩评论

暂无评论...
验证码 换一张
取 消