How can I run symfony 2 run command from controller

前端 未结 9 1454
长发绾君心
长发绾君心 2020-11-28 20:03

I\'m wondering how can I run Symfony 2 command from browser query or from controller.

Its because I don\'t have any possibility on hosting to run it

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 20:18

    same as @malloc but

    use Symfony\Component\Console\Input\ArgvInput;
    use Symfony\Component\Console\Output\ConsoleOutput;
    
    ...
    
    public function myAction() {
      $command = $this->get('MyCommandService');
    
      // $input[0] : command name
      // $input[1] : argument1
      $input = new ArgvInput(array('my:command', 'arg1'));
      $output = new ConsoleOutput();
    
      $command->run($input, $output);
    }
    

提交回复
热议问题