Symfony Doctrineton通过数据库生成Entity文件

这玩意搞得挺蛋疼,后边仔细看了下文档发现还是挺简单的,只需要三步就生成了

1:在src\AppBundle\Resources\config\doctrine文件下生成xml字段映射文件,比如:Test.orm.xml

    php bin/console doctrine:mapping:import  AppBundle xml 这个命令会把默认连接数据库里的所有表都在src\AppBundle\Resources\config\doctrine目录里生成xml文件

如果想要只生成一个表的xml文件只需要加个--filter参数:

php bin/console doctrine:mapping:import  AppBundle --filter=Test xml  Test是表名,第一个字母大写

如果是其他库连接的话可以这样:比如customer连接名称

php bin/console doctrine:mapping:import --force AppBundle xml --em=customer(数据库连接名称)

2:生成Entity目录和test表的字段php文件

php bin/console doctrine:mapping:convert  annotation ./src

或者只生成某个库连接:php bin/console doctrine:mapping:convert annotation ./src --em=customer

如果只生成某个表的Entity实体文件:php bin/console doctrine:mapping:convert annotation --filter=UserLog ./src --em=customer

3:生成set get方法

php bin/console doctrine:generate:entities AppBundle --no-backup   Entity目录里的文件都生成set get方法

或者只想给某个文件生成:

 php bin/console doctrine:generate:entities AppBundle/Entity/Blog --no-backup

你可能感兴趣的:(php)