总结
豆包 AI 助手文章总结

Doctrine248 命令行工具生成yml/xml/entities

php中文网
发布: 2016-07-29 08:58:19
原创
1277人浏览过

doctrine2压缩包的tools目录用来做一些命令行工作。这里主要说一下通过tools,把数据库的表结构自动生成yml/xml/entities,原因是写那些东西太浪费时间了有木有。

1.通过Doctrine 的orm:convert-mapping命令生成xml/yml

Usage:
  orm:convert-mapping [options] [--] <to-type> <dest-path>
  orm:convert:mapping

Arguments:
  to-type                        The mapping type to be converted.
  dest-path                      The path to generate your entities classes.

Options:
      --filter=FILTER            A string pattern used to match entities that should be processed. (multiple values allowed)
      --force                    Force to overwrite existing mapping files.
      --from-database            Whether or not to convert mapping information from existing database.
      --extend[=EXTEND]          Defines a base class to be extended by generated entity classes.
      --num-spaces[=NUM-SPACES]  Defines the number of indentation spaces [default: 4]
      --namespace[=NAMESPACE]    Defines a namespace for the generated entity classes, if converted from database.
  -h, --help                     Display this help message
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi                     Force ANSI output
      --no-ansi                  Disable ANSI output
  -n, --no-interaction           Do not ask any interactive question
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
 Convert mapping information between supported formats.
 
 This is an execute one-time command. It should not be necessary for
 you to call this method multiple times, especially when using the --from-database
 flag.
 
 Converting an existing database schema into mapping files only solves about 70-80%
 of the necessary mapping information. Additionally the detection from an existing
 database cannot detect inverse associations, inheritance types,
 entities with foreign keys as primary keys and many of the
 semantical operations on associations such as cascade.
 
 Hint: There is no need to convert YAML or XML mapping files to annotations
 every time you make changes. All mapping drivers are first class citizens
 in Doctrine 2 and can be used as runtime mapping for the ORM.
 
 Hint: If you have a database with tables that should not be managed
 by the ORM, you can use a DBAL functionality to filter the tables and sequences down
 on a global level:
 
     $config->setFilterSchemaAssetsExpression($regexp);
登录后复制

上面是help,下面来一个实例

/var/www/doctrine$ php vendor/bin/doctrine orm:convert-mapping xml config/xml/ --from-database
登录后复制

 这里linux上执行的命令,先cd到/var/www/doctrine下面(有的菜鸟问了,cd是个什么东东,为毛是这个目录~~cd是什么呢,拜拜,这种问题百度去。为什么是这个目录呢,这是项目文件夹,总之这下面就有doctrine的包了)。前面命令省略解释,解释后面的“xml”意思是生成的文件类型,“config/xml/”是xml存放目录 ,--from-database的意思是从数据库生成。

2.生成yml了,然后就要生成entities了

/var/www/doctrine$ php vendor/bin/doctrine orm:generate-entities src/ --regenerate-entities
登录后复制

 这个简单,我的entities放在/var/www/doctrine/src下面,纯粹测试用,后期架构会变化的

要先生成yml再生成entities,无法直接生成entities,反正我没成功,可能操作问题?

PHP ORM这个文章太少了,因为这个不常用,说白了PHP ORM卵用不大,纯粹方便

以上就介绍了Doctrine248 命令行工具生成yml/xml/entities,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号