【问题标题】:Doctrine load fixtures --no-interaction flag is not working when running in a Symfony commandDoctrine load fixtures --no-interaction 标志在 Symfony 命令中运行时不起作用
【发布时间】:2014-07-20 07:43:36
【问题描述】:

教义:fixtures:load 命令上的--no-interaction 标志无法在 Symfony 命令中运行。但是它正在通过终端工作。我说的对吗?

当我从包中运行它时:

/**
 * Loads the fixtures
 * @param \Symfony\Component\Console\Output\OutputInterface $oOutput
 * @return \Symfony\Component\Console\Output\OutputInterface
 */
protected function loadFixturesCommand($oOutput) {
    $oOutput->writeln('<fg=white>Attempting to load fixtures</fg=white>');
    $updateCommand = $this->getApplication()->find('doctrine:fixtures:load');

    $updateArguments = array(
        'command' => 'doctrine:fixtures:load',
        '--no-interaction' => true,
    );

    $updateInput = new ArrayInput($updateArguments);
    $updateCommand->run($updateInput, $oOutput);

    try {
        $updateCommand->run($updateInput, $oOutput);
    } catch (ContextErrorException $e) {
        //..
    }
    return $this;
} 

系统提示我加载固定装置

但是运行这个:

php app/console doctrine:fixtures:load --no-interaction

不提示我。

我做错了什么?

【问题讨论】:

    标签: symfony doctrine-orm fixtures


    【解决方案1】:

    我找到了解决方案。 只需调用:

    $input->setInteractive(false);
    

    像这样:

    protected function loadFixturesCommand($oOutput) {
        $oOutput->writeln('<fg=white>Attempting to load fixtures</fg=white>');
        $updateCommand = $this->getApplication()->find('doctrine:fixtures:load');
    
        $updateArguments = array(
            'command' => 'doctrine:fixtures:load'
        );
    
        $updateInput = new ArrayInput($updateArguments);
        $updateInput->setInteractive(false);
        $updateCommand->run($updateInput, $oOutput);
    
        try {
            $updateCommand->run($updateInput, $oOutput);
        } catch (ContextErrorException $e) {
            //..
        }
        return $this;
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用--append 参数来抑制交互。

      doctrine:fixtures:load --append

      【讨论】:

      • 附加选项不会在加载数据夹具之前删除您当前的数据库,这就是它不会提示您的原因。 2次通话后,出席结果不能相同
      猜你喜欢
      • 2015-02-15
      • 2018-07-23
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 1970-01-01
      • 2012-08-16
      • 2014-10-08
      • 2021-08-29
      相关资源
      最近更新 更多