2015-01-13 3 views
0

커스텀 커맨드를 빌드하려고합니다. Doctrine이 DB에서 일부 레코드를 받아 SwiftMailer가 이메일을 보내야합니다. 심포니 2.6.1을 사용하십시오. I했습니다 코드 :symfony2.6 doctrine과 swift를 사용한 커스텀 커스텀

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에서 명령을 실행 카운트 날은 항상 같은 오류 사람이 그것을 해결하는 방법을 알고

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();) 

을받을 수?

+0

이 명령을 어떻게 실행하고 있습니까? – Augwa

답변

0

난 당신이 Command documentation을 따라야합니다 같아요

심포니와 함께 자동으로 사용할 수있는 콘솔 명령을하려면 는 Command.php 접미사 PHP 파일 을 번들 내부 명령 디렉토리를 생성하고 생성 제공하려는 각 명령에 대해

클래스 이름도 ReportCommand으로 바꿔야합니다.

+0

이것은 @ Piotr이 – Augwa

+0

클래스 이름 변경, namespacess 및 파일 이동 디렉토리를 작성하는 문제와 관련이 없습니다. 여전히 오류가 있습니다 : ( – Piotr

+0

@Piotr, @AlterPHP 제안은 Bundle 클래스의 트릭 때문에 좋았습니다. [이 기사를보십시오] (http://php-and-symfony.matthiasnoback.nl/ 2013/10/symfony2-console-commands-as-services-why /) – Matteo

1

명령을 실행하는 데 사용자 지정 응용 프로그램을 사용했는데 여기에 뭔가 잘못되었습니다. 내 명령은 앱/콘솔을 통해 실행할 때 제대로 작동합니다.

죄송합니다.

관련 문제