我正在使用Doctrine 2.5
和Slim 3.我有两个实体经理Master和Slave。
在Cli-Config.php文件中,当我创建帮助程序并传递实体Managers及其连接时,如下所示,
$helpers = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($defaultEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($defaultEntityManager),
'db_customer' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($customerEntityManager->getConnection()),
'em_customer' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($customerEntityManager),
]);
return $helpers;
当我尝试命令
时,现在在控制台中php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create
与 $defaultEntityManager
EntityManager相关的架构只会创建与 $customerEntityManager
相关的架构未创建实体管理器。
我可以尝试任何想法/建议吗?
答案 0 :(得分:1)
doctrine的cli脚本期望在返回的HelperSet中定义'em'。这将用于创建架构。
你可以看到它here
要解决这个问题,一种方法是创建两个目录,如:
并在每个脚本中放置2个不同的 cli-config.php 脚本:
$helpers = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($defaultEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($defaultEntityManager),
]);
和
$helpers = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($customerEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($customerEntityManager),
]);
最后,运行:
php ../vendor/doctrine/orm/bin/doctrine orm:schema-tool:create
来自每个目录
或者,您可以根据doctrine `s cli script创建自己的脚本,例如将其命名为“doctrine.php”:
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
require_once __DIR__ . '/vendor/autoload.php';
$commands = [];
$helper1 = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($defaultEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($defaultEntityManager),
]);
$helper2 = new Symfony\Component\Console\Helper\HelperSet([
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($customerEntityManager->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($customerEntityManager),
]);
ConsoleRunner :: run($ helper1,$ commands); ConsoleRunner :: run($ helper2,$ commands);
将其放在项目的根目录下并以:
运行php doctrine.php orm:schema-tool:create
答案 1 :(得分:0)
我的解决方法是:
#!/usr/bin/env php
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;
$commands = [];
$emList = [
$emFoo,
$emBar,
$emZoo
];
foreach ($emList as $em) {
$acpApp = ConsoleRunner::createApplication(ConsoleRunner::createHelperSet($em, $commands));
$acpApp->setAutoExit(false);
$acpApp->run();
}