当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Symfony2 Doctrine Schema Update from Directory and Subdirectories

问题描述:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: