我正在尝试在我的Symfony项目中使用Doctrine进行多连接。
首先,我只使用一个数据库,然后我需要添加另一个数据库。
这是之前的情况:
"然后它运行得很好。接着我添加了“爬行”数据库:"
我取消了自动映射并添加了一些东西,但是现在我失去了与外部网络的连接(例如,用户无法再登录)。有任何想法吗?(如果你读到这里,谢谢;))
编辑:按照http://symfony.com/doc/2.3/reference/configuration/doctrine.html#mapping-entities-outside-of-a-bundle,我尝试使用相同的语法:
首先,我只使用一个数据库,然后我需要添加另一个数据库。
这是之前的情况:
# Doctrine Configuration
doctrine:
dbal:
default_connection: extranet
connections:
extranet:
driver: pdo_mysql
host: "%db_extranet_host%"
port: "%db_extranet_port%"
dbname: "%db_extranet_name%"
user: "%db_extranet_user%"
password: "%db_extranet_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
extranet:
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
"然后它运行得很好。接着我添加了“爬行”数据库:"
# Doctrine Configuration
doctrine:
dbal:
default_connection: extranet
connections:
extranet:
driver: pdo_mysql
host: "%db_extranet_host%"
port: "%db_extranet_port%"
dbname: "%db_extranet_name%"
user: "%db_extranet_user%"
password: "%db_extranet_password%"
charset: UTF8
crawl:
driver: pdo_mysql
host: "%db_crawl_host%"
port: "%db_crawl_port%"
dbname: "%db_crawl_name%"
user: "%db_crawl_user%"
password: "%db_crawl_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: extranet
entity_managers:
extranet:
connection: extranet
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
AppBundle: ~
crawl:
connection: crawl
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
DbBccCrawlBundle: ~
我取消了自动映射并添加了一些东西,但是现在我失去了与外部网络的连接(例如,用户无法再登录)。有任何想法吗?(如果你读到这里,谢谢;))
编辑:按照http://symfony.com/doc/2.3/reference/configuration/doctrine.html#mapping-entities-outside-of-a-bundle,我尝试使用相同的语法:
orm:
# auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: extranet
# auto_mapping: true
mappings:
AppBundle:
type: annotation
dir: '%kernel.root_dir%/../src/AppBundle/Entity'
prefix: AppBundle\Entity
alias: App
DbBccCrawlBundle:
type: annotation
dir: '%kernel.root_dir%/../src/DbBccCrawlBundle/Entity'
prefix: DbBccCrawlBundle\Entity
alias: Crawl
仍然无法工作....
编辑2
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: extranet
entity_managers:
auto_mapping: true
extranet:
connection: extranet
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
AppBundle:
type: annotation
# dir: '%kernel.root_dir%/../src/AppBundle/Entity'
# prefix: AppBundle\Entity
alias: App
crawl:
connection: crawl
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
DbBccCrawlBundle:
type: annotation
# dir: '%kernel.root_dir%/../src/DbBccCrawlBundle/Entity'
# prefix: DbBccCrawlBundle\Entity
alias: Crawl
也不起作用
$em = $this->get('doctrine')->getEntityManager('default');
$em = $this->get('doctrine')->getEntityManager('another');
- Fire Frost