如果我从命令行执行:php bin/console学说:迁移:迁移-n - em =视图
一切都很好。
但是,当我尝试从另一个命令执行此命令时,我不知道如何将InputOption :: value_none params放入arrayinput中。
private function executeMigrate($connection = null) {
$theCommandStr = 'doctrine:migrations:migrate';
$command = $this->getApplication()->find($theCommandStr) ;
if ($command)
{
$arguments = [];
$arguments['-n'] = null; //<-- THE PROBLEM IS HERE!
$arguments['--em'] = 'views';
$input = new ArrayInput($arguments);
$output = new BufferedOutput();
$returnCode = $command->run($input, $output);
if($returnCode == 0) {
echo "OK";
} else {
echo "KO";
}
}
}
我已经测试过(没有运气):$参数[' - n'] = null;$参数[' - n'] =";
使用两个选项,执行了命令,但忽略了-n修饰符。
我正在使用Symfony v.3.3。
已解决。如果您想在其他命令中使用-no Interaction或-n修饰符,则必须使用arrayinput :: setInteractive方法:
以前的代码看起来像:
private function executeMigrate($connection = null) {
$theCommandStr = 'doctrine:migrations:migrate';
$command = $this->getApplication()->find($theCommandStr) ;
if ($command)
{
$arguments = [];
$arguments['--em'] = 'views';
$input = new ArrayInput($arguments);
$input->setInteractive(false);
$output = new BufferedOutput();
$returnCode = $command->run($input, $output);
if($returnCode == 0) {
echo "OK";
} else {
echo "KO";
}
}
}
否则,它行不通。