I want create ContainerAwareCommand in Symfony2 for print email from my database. I have another class, which consist my data. I only start, but what i my do next?
protected function configure()
{
$this
->setName('demo:email:get')
->setDescription('Print all emails form db');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$service = $this->getContainer()->get('fos_elastica.finder.site.user.email');
$output->writeln('<p>%s</p>', $service);
}
But in my console, my command does not exist
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*/);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With