Symfony Command Quick Mail

I am trying to send Swift mail from the command line using the Symfony command. Although I get the following exception.

Fatal error: Call to undefined method Symfony\Bundle\TwigBundle\Debug\TimedTwigE ngine::renderView() in ... 

The container that I got from the command made by ContainerAwareCommand added to this class

The function code is as follows:

 private function sendViaEmail($content) { $message = \Swift_Message::newInstance() ->setSubject('Hello Email') ->setFrom('123@gmail.com') ->setTo('123@gmail.com') ->setBody( $this->container->get('templating')->renderView( 'BatchingBundle:Default:email.html.twig', array('content' => $content) ) ); $this->get('mailer')->send($message); } 

Update The line where the exception occurs is $this->container->get('templating')->renderView(

As you can see in the code, the last line is likely to fail, and it finally gets there.

+8
php swiftmailer symfony
source share
1 answer

As the error message says, TwigEngine does not have a renderView method. renderView() is a shortcut in the Symfony base controller class:

 namespace Symfony\Bundle\FrameworkBundle\Controller class Controller extends ContainerAware { /** * Returns a rendered view. * * @param string $view The view name * @param array $parameters An array of parameters to pass to the view * * @return string The rendered view */ public function renderView($view, array $parameters = array()) { return $this->container->get('templating')->render($view, $parameters); } } 

Here you can see the correct method for rendering a view using the templating service.

 $this->container->get('templating')->render( 'BatchingBundle:Default:email.html.twig', array('content' => $content) ) 
+13
source share

All Articles