Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create ContainerAwareCommand in Symfony2 for print data

Tags:

php

symfony

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

like image 458
Rick Has Avatar asked Sep 07 '26 19:09

Rick Has


1 Answers

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*/);
    }
like image 173
Federkun Avatar answered Sep 10 '26 18:09

Federkun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!