php - Symfony2, Doctrine: Configuring repositories for multiple databases
Get the solution ↓↓↓let's say i have a lot (50+) of repository configurations that begin like this
// in src/Foo/BarBundle/Resources/config/doctrine/Baz.orm.yml
Foo\BarBundle\Entity\Baz:
type: entity
repositoryClass: Foo\BarBundle\Entity\BazRepository
table: foo.bar.baz
i am working with more than one database, they are mostly clones of each other
// in app/config/config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: foo
alpha:
dbname: alpha
bravo:
dbname: bravo
charlie:
dbname: charlie
is there any way for me to change the way the repository configuration handles the table name dinamically ? I tried to inject app parameters in them, but it didn't quite worked.
// in app/config/parameters.yml
parameters:
database_active: charlie
// in src/Foo/BarBundle/Resources/config/doctrine/Baz.orm.yml
Foo\BarBundle\Entity\Baz:
table: %database_active%.bar.baz
[note] i am working with MS SQL Server, but i think the same problem could be applied to PostgreSQL databases
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mysqli::real_connect(): (hy000/2002): connection refused
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.