I have created a command and now I need to call it from a controller. How to do it?

This is the command:

class CleanVarnish extends Command
    protected function configure()
            ->setDescription('Clean Varnish command line');

    protected function execute(InputInterface $input, OutputInterface $output)
        $output->writeln('sudo /usr/bin/varnishadm "ban req.url ~ "/" "');
  • @EvgeniyKapelko he says not to call the exec(), I already have created my command and now I need to call it from the controller – chdzma Jun 14 '18 at 10:02
  • You need to call your custom command file in controller then you can call execute method by that files object. May I know why you want to call command in your controller? actually, you can copy code from that command file amd put that in your controller. – kunj Jun 14 '18 at 10:12
  • @kunj Is to run it from the backend, could you give me an example? – chdzma Jun 14 '18 at 10:21
  • Check this: stackoverflow.com/questions/36748588/… – kunj Jun 14 '18 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.