【发布时间】:2017-10-05 13:46:21
【问题描述】:
我正在编写一个 PHP Silex 应用程序,并且我想使用多个 OMS 实体管理器。我已按照Silex\Provider\DoctrineServiceProvider 的说明添加多个命名数据库
$dbs_options = [
"base" => [
"driver" => "pdo_sqlite",
"path" => "C:\users\russells\workspaces\turlesystems\database\dev.sqlite"
]
];
$app -> register(new DoctrineServiceProvider, ['dbs.options' => $dbs_options]);
我已经配置了 EntityManagers:
$mappings = [
[
'type' => 'annotation',
'namespace' => 'Turtle\Model\Entity',
'path' => "c:\users\russells\workspaces\fisheagle\Turtle\Model\Entity",
'use_simple_annotation_reader' => false
]
];
$app -> register(new DoctrineOrmServiceProvider, [
'orm.proxies_dir' => Utils::joinPaths($app -> config -> appRoot, 'running', 'proxies'),
'orm.em.options' => [
'mappings' => $mappings
]
]
);
$app['orm.ems.default'] = 'basedb';
$app['orm.ems.options'] = [
'basedb' => [
'connection' => 'base',
'mappings' => $app['orm.em.options']['mappings']
]
];
然后我尝试在存储库上执行 findAll() 操作,但我的应用程序崩溃了,或者更确切地说,显示状态存在异常,但我在日志中没有看到异常,try ... catch 也没有显示任何内容。
dump("Retrieve Entity Manager");
$em = $this -> app['orm.ems']['basedb'];
dump("Get Repo");
$repo = $em -> getRepository("\Turtle\Model\Entity\WebsiteDomain");
dump("Get all items");
$items = $repo -> findAll();
dump("Display items");
dump($items);
我正在使用PHP内置的Web服务器运行该应用程序,日志如下:
PHP 7.1.8 Development Server started at Thu Oct 5 14:42:32 2017
Listening on http://0.0.0.0:10000
Document root is C:\Users\russells\workspaces\turtlesystems\fisheagle\web\local
Press Ctrl-C to quit.
[Thu Oct 5 14:43:43 2017] 127.0.0.1:65116 [200]: /
[Thu Oct 5 14:43:45 2017] 127.0.0.1:65117 Invalid request (Unexpected EOF)
[Thu Oct 5 14:43:45 2017] 127.0.0.1:65119 Invalid request (Unexpected EOF)
我被难住了。如果我在配置中只使用一个 EM,我的应用程序可以正常工作,只有在我尝试使用 orm.ems 选项时才会发生这种情况。有没有我遗漏的非常简单的东西。
我使用的是 PHP 7.1 和 Silex 2。这段代码在 Windows 上运行,我还没有在 Linux 上尝试过,但是鉴于一个 EM 可以工作,我感觉这不是问题。
【问题讨论】:
标签: php doctrine-orm silex