正在尝试构建自定义命令。需要通过原则从数据库获得一些记录,并通过SwiftMailer发送电子邮件。使用symfony 2.6.1。我已经编写了代码:
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);
}
}当我在控制台raport:count-day中运行命令时,总是收到相同的错误
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();)有人知道怎么解决这个问题吗?
发布于 2015-01-14 00:27:17
我使用自定义应用程序来运行命令,在这里我做了一些错误的事情。当我通过应用程序/控制台运行时,我的命令可以正常工作
抱歉的
发布于 2015-01-13 23:12:44
我想你应该关注Command documentation:
PHP要使控制台命令在Symfony中自动可用,请在捆绑包中创建一个PHP命令目录,并为您想要提供的每个命令创建一个文件,后缀是Command.php。
您的类也应该重命名为ReportCommand。
https://stackoverflow.com/questions/27925031
复制相似问题