我有一个产品可供许多客户使用,但我希望有一个代码库。每个客户都需要对数据库(实体转发)和自己的主题进行一些特定的更改。每个客户都有自己的数据库。我需要找到一个解决方案,为每个客户在配置中定义必须读取的实体,以创建或更新他自己的数据库模式。
在我的捆绑包中,实体中有这种结构
AcmeJobBundleEntitiesCustomer.php
AcmeJobBundleEntitiesCustomer1Customer.php
AcmeJobBundleEntitiesCustomer2Customer.php
AcmeJobBundleEntitiesCustomer3Customer.php
AcmeJobBundleEntitiesCustomer.php is an abstract class
AcmeJobBundleEntitiesCustomer1Customer.php extends AcmeJobBundleEntitiesCustomer.php
感谢您抽出时间
根据Symfony2文档:
您可以定义多实体管理器和相关映射:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
customer:
driver: "%database_driver2%"
host: "%database_host2%"
port: "%database_port2%"
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
AppBundle: ~
AcmeStoreBundle: ~
customer:
connection: customer
mappings:
AcmeCustomerBundle: ~
当然,你可以创建这样的模式:
# Play only with "default" mappings
$ php app/console doctrine:schema:update --force
# Play only with "customer" mappings
$ php app/console doctrine:schema:update --force --em=customer