gpt4 book ai didi

php - 名为 “db2” 的 Symfony2 Doctrine ORM 管理器不存在

转载 作者:搜寻专家 更新时间:2023-10-31 21:25:04 24 4
gpt4 key购买 nike

我创建 YML 实体,生成实体并配置多个连接

配置.yml

# Doctrine Configuration
doctrine:
dbal:
default_connection: db1
connections:
db1:
driver: '%database_driver%'
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
db2:
driver: '%database_driver2%'
host: '%database_host2%'
port: '%database_port2%'
dbname: '%database_name2%'
user: '%database_user2%'
password: '%database_password2%'
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true

我的orm.yml

TestBundle\Entity\Test:
type: entity
table: Test
id:
id:
type: integer
nullable: false
options:
unsigned: true
id: true
fields:
name:
type: string
nullable: false
length: 255
options:
fixed: false
lifecycleCallbacks: { }

清理缓存并生成实体后,我尝试运行此代码(在命令 Controller 中)

<?php 

...

protected function execute(InputInterface $input, OutputInterface $output)
{
$doctrine = $this->getContainer()->get('doctrine')->getManager('db2');
//both methods cant work :( db2_entity_manager not found
$doctrine = $this->getContainer()->get('doctrine.orm.db2_entity_manager');

$test = $doctrine->getRepository('DionisDataBaseBundle:Test');

}

我有错误:

[InvalidArgumentException]
Doctrine ORM Manager named "db2" does not exist.

最佳答案

将 config.yml 更改为

 orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: db1
entity_managers:
db1:
connection: db1
mappings:
DionisDataBaseBundle: ~
db2:
connection: db2
mappings:
DionisDataBaseBundle: ~
db3:
connection: db2
mappings:
DionisDataBaseBundle: ~

关于php - 名为 “db2” 的 Symfony2 Doctrine ORM 管理器不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37993232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com