【发布时间】:2016-01-15 22:05:12
【问题描述】:
在 Symfony2 应用程序中,我正在尝试通过控制器运行迁移脚本,如下所示:
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\Response;
class SpoolController extends Controller
{
public function migrateAction($entity_manager = 'default')
{
$kernel = $this->get('kernel');
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput(array(
'command' => 'doctrine:migrations:migrate',
'--em' => $entity_manager,
));
// You can use NullOutput() if you don't need the output
$output = new BufferedOutput();
$application->run($input, $output);
// return the output, don't use if you used NullOutput()
$content = $output->fetch();
// return new Response(""), if you used NullOutput()
return new Response($content);
}
}
当我没有在命令中指定迁移脚本名称时,上面的代码正在工作。但是当我在命令中指定版本号时,如下所示:
$input = new ArrayInput(array(
'command' => 'doctrine:migrations:migrate 20150916202248',
'--em' => 'codes',
));
然后我收到错误:
string '[InvalidArgumentException] 命令 “教义:迁移:迁移 20150916202248”未定义。你是否 意思是其中之一?学说:迁移:状态 学说:迁移:差异 学说:迁移:执行'...(长度=880)
不能通过控制器运行特定版本的文件吗?
【问题讨论】:
标签: symfony