在 Silex 中声明多个 Doctrine EntityManagers 时如何使用 `orm.ems`?

How can I use `orm.ems` when declaring multiple Doctrine EntityManagers in Silex?

我正在编写 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 有效我感觉这不是问题。

我已经解决了我的问题。原来是数据库的路径,因为我用的是"\转义字符,这意味着找不到数据库文件。

我在意识到我没有 运行 处于调试模式后发现了这个,当我这样做时,我得到了我需要的错误消息。我将此添加到我的代码中:

$app['debug'] = true