I've now read kinda half of the Doctrine 2 documentation but I can't find a solution: how do I create a table for a class automatically using Doctrine?
我现在已经读了大约一半的Doctrine 2文档,但是我找不到一个解决方案:如何为一个类创建一个自动使用Doctrine的表?
Do I really need to work with XML/YAML or some other stuff than PHP itself? Do I really need DQL for that? Doesn't Doctrine find the names and all this stuff for me?
我是否真的需要使用XML/YAML或其他东西,而不是PHP本身?我真的需要DQL吗?教条不为我找到名字和所有这些东西吗?
2 个解决方案
#1
2
First of all, you have to understand that in Doctrine 2 there are three elements that play together:
首先,你必须明白,在教义2中有三个因素在起作用:
- entities (just plain PHP classes)
- 实体(普通的PHP类)
- mappings (additional markup that you place on entities or in related classes)
- 映射(在实体或相关类中放置的附加标记)
- database
- 数据库
Doctrine reads your entities and your mappings and connects every entity and its fields to the related database fields.
Doctrine读取实体和映射,并将每个实体及其字段连接到相关的数据库字段。
The generation of the database is done by the Doctrine\ORM\Tools\SchemaTool
(SchemaTool) class, which can read metadata and define how your schema should like.
数据库的生成是由Doctrine\ORM\Tools\SchemaTool (SchemaTool)类完成的,它可以读取元数据并定义模式应该如何。
Doctrine's CLI, as said by @Marcin, provides the orm:schema-tool:create
and orm:schema-tool:update
commands, which are just wrappers for the SchemaTool
. They help you getting started fast and keep your schema in sync with your entity definitions.
如@Marcin所说,Doctrine的CLI提供了orm:schema-tool:create和orm:schema-tool:update命令,它们只是SchemaTool的包装。它们帮助您快速启动并保持您的模式与实体定义同步。
#2
1
I'm not sure if I understood you correctly. If you want to create a structure in a database, use the console function orm:schema-tool:create
我不确定我是否理解正确。如果希望在数据库中创建结构,请使用控制台函数orm:schema-tool:create
#1
2
First of all, you have to understand that in Doctrine 2 there are three elements that play together:
首先,你必须明白,在教义2中有三个因素在起作用:
- entities (just plain PHP classes)
- 实体(普通的PHP类)
- mappings (additional markup that you place on entities or in related classes)
- 映射(在实体或相关类中放置的附加标记)
- database
- 数据库
Doctrine reads your entities and your mappings and connects every entity and its fields to the related database fields.
Doctrine读取实体和映射,并将每个实体及其字段连接到相关的数据库字段。
The generation of the database is done by the Doctrine\ORM\Tools\SchemaTool
(SchemaTool) class, which can read metadata and define how your schema should like.
数据库的生成是由Doctrine\ORM\Tools\SchemaTool (SchemaTool)类完成的,它可以读取元数据并定义模式应该如何。
Doctrine's CLI, as said by @Marcin, provides the orm:schema-tool:create
and orm:schema-tool:update
commands, which are just wrappers for the SchemaTool
. They help you getting started fast and keep your schema in sync with your entity definitions.
如@Marcin所说,Doctrine的CLI提供了orm:schema-tool:create和orm:schema-tool:update命令,它们只是SchemaTool的包装。它们帮助您快速启动并保持您的模式与实体定义同步。
#2
1
I'm not sure if I understood you correctly. If you want to create a structure in a database, use the console function orm:schema-tool:create
我不确定我是否理解正确。如果希望在数据库中创建结构,请使用控制台函数orm:schema-tool:create