gpt4 book ai didi

database - zf3 中的 doctrine2 多数据库连接?

转载 作者:搜寻专家 更新时间:2023-10-30 20:35:07 24 4
gpt4 key购买 nike

我在 zf3 中使用了 doctrine2,同时连接多个数据库导致错误。下面是我在 global.php 中的配置

return [
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => PDOMySqlDriver::class,
'params' => [
'host' => '127.0.0.1',
'user' => 'root',
'password' => '123456',
'dbname' => 'zf3.com',
'charset' => 'utf8',
]
],
'orm_passport' => [
'driverClass' => PDOMySqlDriver::class,
'params' => [
'host' => '127.0.0.1',
'user' => 'root',
'password' => '123456',
'dbname' => 'zf3.com.passport',
'charset' => 'utf8',
]
],
],
'entitymanager' => [
'orm_passport' => [
'connection' => 'orm_passport',
]
],
],
];

module.config.php 中的驱动配置如下:

'doctrine' => [
'driver' => [
__NAMESPACE__ . '_driver' => [
'class' => AnnotationDriver::class,
'cache' => 'array',
'paths' => [__DIR__ . '/../src/Entity']
],
'orm_passport' => [
'drivers' => [
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
]
]
]
],

在我的 IndexController.php 中

 public function indexAction()
{
// Get recent users
$users = $this->entityManager->getRepository(Users::class)
->findBy(['status'=>Users::ACTIVE_STATUS_NO],['timeCreated'=>'DESC']);

//\Doctrine\Common\Util\Debug::dump($users);

return new ViewModel([
'users' => $users
]);
}

错误信息:在链配置的命名空间 Application\Entity 中找不到类“Passport\Entity\Users”

最佳答案

下面是我的global.php

return [
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => PDOMySqlDriver::class,
'params' => [
'host' => '127.0.0.1',
'user' => 'root',
'password' => '123456',
'dbname' => 'zf3.com',
'charset' => 'utf8',
]
],
'orm_passport' => [
'driverClass' => PDOMySqlDriver::class,
'params' => [
'host' => '127.0.0.1',
'user' => 'root',
'password' => '123456',
'dbname' => 'zf3.com.passport',
'charset' => 'utf8',
]
],
],
'entitymanager' => [
'orm_passport' => [
'connection' => 'orm_passport',
'configuration' => 'orm_passport',
]
],
'migrations_configuration' => [
'orm_passport' => [
'directory' => 'data/DoctrineORMModule/Migrations',
'name' => 'Doctrine Database Migrations',
'namespace' => 'DoctrineORMModule\\Migrations',
'table' => 'migrations',
'column' => 'version',
],
],
'configuration' => [
'orm_passport' => [
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'hydration_cache' => 'array',
'driver' => 'orm_passport',
'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineORMModule/Proxy',
'proxy_namespace' => 'DoctrineORMModule\\Proxy',
]
],
'authentication' => [
'odm_passport' => [],
'orm_passport' => [
'objectManager' => 'doctrine.entitymanager.orm_passport',
],
],
'authenticationadapter' => [
'odm_passport' => true,
'orm_passport' => true,
],
'authenticationstorage' => [
'odm_passport' => true,
'orm_passport' => true,
],
'authenticationservice' => [
'odm_passport' => true,
'orm_passport' => true,
],
],
];

它有效!

关于database - zf3 中的 doctrine2 多数据库连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43776357/

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