Create ContainerAwareCommand in Symfony2 for print data Create ContainerAwareCommand in Symfony2 for print data symfony symfony

Create ContainerAwareCommand in Symfony2 for print data


Follows the documentation.

In short, add execute() method to the class, get your service from the container, then display the data.

   protected function execute(InputInterface $input, OutputInterface $output)    {        $service = $this->getContainer()->get('your_service.database_connection');        $email = // work with $service        $output->writeln(/*here you render the data*/);    }


May be you're doing something wrong, check class name, directory name, etc. From the doc:

To make the console commands available automatically with Symfony, create a Command directory inside your bundle and create a PHP file suffixed with Command.php for each command that you want to provide. For example, if you want to extend the AppBundle to greet you from the command line, create GreetCommand.php