Reputation: 13
Trying to build a custom command. Need get some records from DB by Doctrine and send email by SwiftMailer. Use symfony 2.6.1. I've code:
namespace MyBundle\Console\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Raport extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('raport:count-day')
->setDescription('test');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getManager();
$em->getRepository('My:Application')->findAll();
// $output->writeln($text);
}
}
When I run command in console raport:count-day always receive the same error
PHP Fatal error: Call to undefined method Symfony\Component\Console\Application::getKernel() in /var/www/auto/pzu-voucher/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php on line 42 ($this->container = $application->getKernel()->getContainer();)
anyone knows how to solve it?
Upvotes: 0
Views: 579
Reputation: 13
I used custom application to run commands, and here I had done something wrong. My commands works correctly when I run it via the app/console
sorry
Upvotes: 1
Reputation: 12727
I guess you should follow Command documentation :
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.
Your class should also be renamed to ReportCommand
.
Upvotes: 0