我想从我的控制器执行命令 fos:elastica:populate。
我尝试了该代码,但它不起作用,我得到 error = 1 the var_dump show ""
$command = 'fos:elastica:populate';
$app = new Application($this->get('kernel'));
$app->setAutoExit(false);
$input = new StringInput($command);
$output = new ConsoleOutput;
$error = $app->run($input, $output);
var_dump($error);
var_dump(stream_get_contents($output->getStream());
有任何想法吗 ?
我尝试不同的代码......
$command = $this->get('FosElasticaPopulateService');
$input = new StringInput('');
$output = new ConsoleOutput();
ladybug_dump($input);
// Run the command
$retval = $command->run($input, $output);
if(!$retval)
{
echo "Command executed successfully!\n";
}
else
{
echo "Command was not successful.\n";
}
var_dump(stream_get_contents($output->getStream()));
它说:“不存在“无交互”选项。在 PopulateCommand 中的 Input ->getOption ('no-interaction') 处。
如果我更改我的代码:
$input = new StringInput('--no-interaction');
它说:'“--no-interaction”选项不存在。' 在
'ArgvInput -> addLongOption('无交互',null)'