2013-09-02 2 views
3

symfony 사이트에 대한 크론 작업이 필요합니다. 내가 콘솔 명령을 만들 자습서를 발견 http://symfony.com/doc/2.1/cookbook/console/console_command.html콘솔 명령의 symfony2 문서 관리자

내 command.php

네임 스페이스 XXX에서 \ WebBundle 명령 \;

사용 심포니 \ 구성 요소 \ 콘솔 \ 명령 \ 명령; Symfony \ Component \ Console \ Input \ InputArgument; 을 사용하십시오. Symfony \ Component \ Console \ Input \ InputInterface; 을 사용하십시오. Symfony \ Component \ Console \ Input \ InputOption; 을 사용하십시오. Symfony \ Component \ Console \ Output \ OutputInterface; 을 사용하십시오. "\ WebBundle 명령 \ XXXX 정의되지 않은 메서드에

클래스 GreetCommand이 명령을 확장 { 보호 기능 구성() {

} 

protected function execute(InputInterface $input, OutputInterface $output) 
{ 

    $em = $this->getContainer()->get('doctrine')->getManager(); 
    $em->getRepository('xxxWebBundle:Wishlist')->findAll(); 
    // $output->writeln($text); 
} 

}

나는 오류가 콘솔에서 명령을 호출 전화 \ MyCommand :: getContainer() " 문서 관리자가 실행 기능을 얻으려면 어떻게해야합니까?

답변

6

당신은에이 $this->getContainer()

namespace xxx\WebBundle\Command; 

//Don't forget the use 
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 
use Symfony\Component\Console\Input\InputArgument; 
use Symfony\Component\Console\Input\InputInterface; 
use Symfony\Component\Console\Input\InputOption; 
use Symfony\Component\Console\Output\OutputInterface; 

class GreetCommand extends ContainerAwareCommand { 
    protected function configure() {} 

    protected function execute(InputInterface $input, OutputInterface $output) 
    { 

    $em = $this->getContainer()->get('doctrine')->getManager(); 
    $em->getRepository('xxxWebBundle:Wishlist')->findAll(); 
    // $output->writeln($text); 
    } 
} 
에 액세스 할 수 있도록 ContainerAwareCommand을 확장 필요
관련 문제