command로 swiftmailer를 이용하여 메일 전송 시 renderView()에 대한 에러
- 0
-
0
symfony2.7 버전에서 command로 메일을 전송하려고 하는데 renderView에 대한 메소드가 정의되어 있지 않다는 에러가 발생하네요
동일한 소스로 controller 동작시키면 정상인걸로 봐선 코드상의 문제는 아닌거 같은데.. 도움 요청드립니다.
- <?php
- namespace CronBundle\Command;
- 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 CronCommand extends ContainerAwareCommand
- {
- protected function configure()
- {
- $this->setName('send')
- }
- protected function execute(InputInterface $input, OutputInterface $output)
- {
- $messasge = \Swift_Message::newInstance()
- ->setSubject('Hello World!!')
- ->setFrom('a@a.com')
- ->setTo('a@a.com')
- ->setContentType('text/html')
- ->setBody($this->renderView(
- 'CronBundle:Email:default.html.php', array()
- )
- );
- $this->get('mailer')->send($messasge);
- $output->writeln('Success!!');
- }
- }
콘솔 실행 명령어 : php app/console send
- [Symfony\Component\Debug\Exception\UndefinedMethodException]
- Attempted to call an undefined method named "renderView" of class "CronBundle\Command\CronCommand".
0
댓글
작성한 댓글 등록하기
renderView()는 Controller에서 사용가능한 메소드 입니다.
- ->setBody($this->renderView(
변경:
- ->setBody($this->getContainer()->get('templating')->render(
추가적으로 mailer도 변경해 주세요
- $this->get('mailer')->send($messasge);
변경:
- $this->getContainer()->get('mailer')->send($messasge);
답변 작성
질문에 적합한 답변을 상세히 작성해 주시기 바랍니다.
답변이 찬성되면 태그평판 +2점이 적립, 반대되면 태그평판 -1점 차감됩니다.
답변이 채택되면 태그평판 +10점이 적립됩니다.