Propel 可以根据模式文件生成类。一些生成的类是:
- 对象(例如用户)
- 对等点(例如 UserPeer)
- 查询(例如 UserQuery)
对象类(用户)包括所有属性的 getter 和 setter。例如
$user = new User();
echo $user->getEmailAddress();
我的问题是:Doctrine 2.0 可以做到这一点吗?它是否生成基类并添加 getter 和 setter?
最佳答案
是的,Doctrine 2 确实支持类生成的模式,我更喜欢 YAML 而不是 XML,所以这里是覆盖 http://www.doctrine-project.org/docs/orm/2.0/en/reference/yaml-mapping.html 的链接
然后通过 Doctrine 命令行工具,您可以获取提供的 YML 文件并生成 http://www.doctrine-project.org/docs/orm/2.0/en/reference/tools.html
关于你的第二个问题,在大多数情况下,Doctrine 确实有简单的 setter/getter,但在 Doctrine 术语中它们被称为访问器方法。
更新:
对于完全生成的类,给出如下表格
user:
id: integer
name: string
active: bool
它将是 $user->getName() 和 $user->setName("Joe"), $user->setActive(true) 和 $user->getActive();
通过查看 Doctrine 2 git repo https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/EntityGenerator.php 中的这个文件,可以稍微了解它如何生成这些中间类。
关于php - Doctrine 2.0 是否像 Propel 1.5 那样预先生成模型类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5954618/