首先我要感谢大家看我的问题。这是我的问题。在控制器中运行多个控制台命令Symfony 2
我想在控制器中运行Symfony 2中的三个现有控制台命令。所以我为此写了三个独立的函数(见下文)。我设法运行'学说:映射:导入'(找到下面的代码),没有任何问题在控制器内。接下来我想要做的是根据导入的映射文件生成实体。我无法运行'学说:生成:实体'命令,而无需关闭和引导内核(我认为这是一个坏主意,请看下面的代码)。不关闭和引导内核,它不会为我生成实体。但关闭并引导内核后,它为我创建实体(现在我有点高兴)。我遇到的下一个问题是当我运行'学说:生成:形式'命令(查找下面的代码)。当我在生成实体之后运行此代码时,它会说'Class''我的CLASS'的名称'不存在'。这不可能发生。因为我在生成实体之后运行表单构建命令。即使我尝试通过物理访问文件来搜索课程实际上是否存在。它就在那里。所以我完全停留在这里,我会说。
嗯,我知道这是一个漫长的问题。如果有人能够知道是什么原因导致生成实体不创建实体,而不关闭并引导内核和表单生成器命令不起作用,即使实体文件存在,也会真正感激。有一点我注意到,但是当我每次运行一个时,这个命令(3个函数)工作正常。但我想一个接一个地称这三个功能。所以主要是我顺序调用这3个函数时发生的问题。
代码为 '学说:映射:进口'
public function executeImportCommandAction($filter)
{
$kernel = $this->container->get('kernel');
$app = new Application($kernel);
$app->setAutoExit(false);
$input = new \Symfony\Component\Console\Input\ArrayInput(
array('command' => 'doctrine:mapping:import', 'bundle' => 'TESTClientBundle', '--filter'
=> $filter, 'mapping-type' => 'yml'));
$app->doRun($input, new \Symfony\Component\Console\Output\ConsoleOutput());
}
代码为“学说:生成:实体的
public function executeBuildFormCommandActions($entity)
{
$kernel = $this->container->get('kernel');
$kernel->shutdown();
$kernel->boot();
$app = new Application($kernel);
$app->setAutoExit(false);
$input = new \Symfony\Component\Console\Input\ArrayInput(
array('command' => 'doctrine:generate:entities', 'name' => 'TESTClientBundle',
'--no-backup' => 'true'));
$app->doRun($input, new \Symfony\Component\Console\Output\ConsoleOutput());
}
代码为 '学说:生成:形式'
public function executeBuildFormCommandActions($entity)
{
#$kernel = $this->container->get('kernel');
$app = new Application($kernel);
$app->setAutoExit(false);
$input = new \Symfony\Component\Console\Input\ArrayInput(
array('command' => 'doctrine:generate:form', 'entity' => 'TESTVClientBundle:'.$entity.''));
$app->doRun($input, new \Symfony\Component\Console\Output\ConsoleOutput());
}
非常感谢。 干杯!
使用过程更好,但如何在控制器中运行多个命令?这是个问题。 –
@VincentGuyard上面的函数已经在Controller中。仔细看看它。干杯:) –
当我用新的Process()执行命令时,我的php冻结并且不允许我执行另一个命令。我所做的是在每个命令之间使用“&&”执行我所有的命令。 (是的,我知道,您的代码位于控制器内部) –