Generate Entities with Doctrine into separate namespace(使用 Doctrine 生成实体到单独的命名空间中)
问题描述
我正在关注这里的文档:
I'm following the documentation here:
- http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
这些是命令
php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force
php app/console doctrine:mapping:import AcmeBlogBundle annotation
php app/console doctrine:generate:entities AcmeBlogBundle
我在这里看到了新的实体"
I see the new Entities here in"
Acme/BlogBundle/AcmeBlogBundle/Entity
但我想知道如何像这样将实体添加到他们自己的命名空间中
But I wanted to know how I could add the Entities into their own namespace like this
Acme/BlogBundle/AcmeBlogBundle/Entity/Foo
Acme/BlogBundle/AcmeBlogBundle/Entity/Bar
这样我就可以将 Foo 和 Bar 数据库的实体分开.
This is so I could keep the Entities for Foo and Bar Databases separated.
更新:
或者应该是这样的结构:
Or should it be structured like this:
Acme/BlogBundle/AcmeBlogBundle/Foo/Entity
Acme/BlogBundle/AcmeBlogBundle/Bar/Entity
想法?
推荐答案
如果你看看 How要使用文档的多个实体管理器和连接部分,您会注意到您可以将捆绑实体绑定到一个或多个 实体管理器.它们中的每一个都与特定的数据库连接相关.
If you take a look at How to work with Multiple Entity Managers and Connections section of the documentation, you'll notice that you can bind your bundle entities to one or many entity managers. Each one of them related to a specific database connection.
例如,如果我定义了两个数据库连接(first_connection 和 second_connection),我可以添加两个实体管理器,如下所示,
If for example I've defined two database connections (first_connection and second_connection), I can than add two entity managers as follow,
entity_managers:
first_manager:
connection: first_connection
mappings:
MyBundle:
dir: Path/To/EntityFolder/Foo/
second_manager:
connection: second_connection
mappings:
MyBundle:
dir: Path/To/EntityFolder/Bar/
然后,您可以指定在实体生成过程,
php app/console doctrine:mapping:convert xml ./src/Acme/BlogBundle/Resources/config/doctrine/metadata/orm --from-database --force --em=first_manager --filter=MyTable
注意: --filter
选项用于允许您单独生成实体.
Note: The --filter
option is used to allow you generate your entities individually.
php app/console doctrine:mapping:import AcmeBlogBundle annotation --em=first_manager --filter=MyTable
php app/console doctrine:generate:entities AcmeBlogBundle
然后根据绑定的连接将您的实体放入正确的文件夹中.
Your entities are then put into the right folders according to the connection the were bound to.
这篇关于使用 Doctrine 生成实体到单独的命名空间中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Doctrine 生成实体到单独的命名空间中
基础教程推荐
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01