How can I run symfony 2 run command from controller

前端 未结 9 1453
长发绾君心
长发绾君心 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条回答
  •  佛祖请我去吃肉
    2020-11-28 20:23

    In my environment ( Symony 2.1 ) I had to do some modifications to @Reuven solution to make it work. Here they are:

    Service definition - no changes.

    In controller:

    use Symfony\Component\Console\Input\ArgvInput;
    use Symfony\Component\Console\Output\ConsoleOutput;
    
    ...
    
    public function myAction() {
        $command = $this->get('MyCommandService');
    
        $input = new ArgvInput(array('arg1'=> 'value'));
        $output = new ConsoleOutput();
    
        $command->run($input, $output);
    }
    

提交回复
热议问题