command로 swiftmailer를 이용하여 메일 전송 시 renderView()에 대한 에러
조회수 4573 답변수 1 반응수 1 등록일 2016.08.11 01:43:47

symfony2.7 버전에서 command로 메일을 전송하려고 하는데 renderView에 대한 메소드가 정의되어 있지 않다는 에러가 발생하네요

동일한 소스로 controller 동작시키면 정상인걸로 봐선 코드상의 문제는 아닌거 같은데.. 도움 요청드립니다.

  1. <?php
  2. namespace CronBundle\Command;
  3.  
  4. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  5. use Symfony\Component\Console\Input\InputArgument;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Input\InputOption;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9.  
  10. class CronCommand extends ContainerAwareCommand
  11. {
  12.     protected function configure()
  13.     {
  14.         $this->setName('send')
  15.     }
  16.  
  17.     protected function execute(InputInterface $input, OutputInterface $output)
  18.     {   
  19.         $messasge = \Swift_Message::newInstance()
  20.             ->setSubject('Hello World!!')
  21.             ->setFrom('a@a.com')
  22.             ->setTo('a@a.com')
  23.             ->setContentType('text/html')
  24.             ->setBody($this->renderView(
  25.                     'CronBundle:Email:default.html.php', array()
  26.                 )
  27.             );
  28.  
  29.         $this->get('mailer')->send($messasge);
  30.         $output->writeln('Success!!');
  31.     }
  32. }


콘솔 실행 명령어 :  php app/console send


  1. [Symfony\Component\Debug\Exception\UndefinedMethodException]
  2.   Attempted to call an undefined method named "renderView" of class "CronBundle\Command\CronCommand".


renderView()는 Controller에서 사용가능한 메소드 입니다.

  1. ->setBody($this->renderView(

변경:

  1. ->setBody($this->getContainer()->get('templating')->render(


추가적으로  mailer도 변경해 주세요

  1. $this->get('mailer')->send($messasge);

변경:

  1. $this->getContainer()->get('mailer')->send($messasge);


2016.08.11 22:09:53 반응 이력
감사합니다~ 초급 2016.08.12 02:12:58

답변 작성

질문에 적합한 답변을 상세히 작성해 주시기 바랍니다.

답변이 찬성되면 태그평판 +2점이 적립, 반대되면 태그평판 -1점 차감됩니다.

답변이 채택되면 태그평판 +10점이 적립됩니다.

etc 게시판 정보
  • 1.7k
    질문수
  • 100
    아카이브수
  • 46
    채택수
  • 0
    멤버수
etc 질문 통계
최근 30일
답변율
6%
채택율
0%
전체
답변율
3%
채택율
2%
최근에 등록된 질문