How can I run symfony 2 run command from controller

前端 未结 9 1431
长发绾君心
长发绾君心 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:03

    You can just simply create an instance of your command and run it:

    /**
     * @Route("/run-command")
     */
    public function someAction()
    {
        // Running the command
        $command = new YourCommand();
        $command->setContainer($this->container);
    
        $input = new ArrayInput(['--your_argument' => true]);
        $output = new ConsoleOutput();
    
        $command->run($input, $output);
    
        return new Response();
    }
    

提交回复
热议问题