目录和子目录的Symfony2教义模式更新 [英] Symfony2 Doctrine Schema Update from Directory and Subdirectories
问题描述
我有很多客户的产品,但我想要有一个代码库。每个客户需要在数据库(实体回馈)和他自己的主题中进行一些具体的更改。每个客户都有自己的数据库。我需要找到一个解决方案,在配置中为每个客户定义必须读取的实体,以创建或更新自己的数据库模式。
在我的捆绑包中,我有这个结构实体
Acme\JobBundle\Entities\Customer.php
Acme\JobBundle\Entities\ Customer1\Customer.php
Acme\JobBundle\Entities\Customer2\Customer.php
Acme\JobBundle\Entities\Customer3\Customer.php
Acme\JobBundle\Entities\Customer.php是一个抽象类
Acme\JobBundle\Entities\Customer1\Customer.php extends Acme\JobBundle\Entities\\ \\ Customer.php
感谢您的时间
根据 Symfony2 doc :
哟你可以定义多个实体管理器和相关的映射:
doctrine:
dbal:
default_connection:default
连接:
默认值:
驱动程序:%database_driver%
主机:%database_host%
端口:%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%
密码:%database_password2%
字符集:UTF8
orm:
default_entity_manager:默认
entity_ma nagers:
默认值:
连接:默认
映射:
AppBundle:〜
AcmeStoreBundle:〜
客户:
连接:客户
映射:
AcmeCustomerBundle:〜
当然,您可以创建这样的模式:
#仅使用默认映射
/ pre>
$ php app / console doctrine:schema:update --force
#仅使用客户映射
$ php应用程序/控制台原则:模式:update --force --em = customer
I have one product for many customers but I want to have one code base. Every customer needs some specific changes in database(entities repos) and in his own themes. Every customer has his own database. I need to find a solution to define in configuration for every customer witch entities must be read to create or update his own database schema.
In my bundles i have this structure in Entities
Acme\JobBundle\Entities\Customer.php Acme\JobBundle\Entities\Customer1\Customer.php Acme\JobBundle\Entities\Customer2\Customer.php Acme\JobBundle\Entities\Customer3\Customer.php Acme\JobBundle\Entities\Customer.php is an abstract class Acme\JobBundle\Entities\Customer1\Customer.php extends Acme\JobBundle\Entities\Customer.php
Thank you for your time
解决方案Accordingly to the Symfony2 doc:
You can define multi entity managers and the associated mapping:
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: ~
And of course you can create your schema like this:
# 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
这篇关于目录和子目录的Symfony2教义模式更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!