php - Symfony templating array doesn't work -


i use symfony. created helper class sendmessage

use symfony\component\dependencyinjection\containerinterface container;  class sendmessage {     private $container;      public function __construct(container $container) {         $this->container = $container;     }      public function addentitymessage($creator, $projectname, $type, $sendto)     {         $mailer = $this->container->get('mailer');         $message = \swift_message::newinstance()             ->setsubject('hello email')             ->setfrom('emailfrom@gmail.com')             ->setto($sendto)             ->setbody(                 $this->container->get('templating')                     ->render('mybundle:email:new_entity.html.twig'), array(                     'creator' => $creator,                     'name' => $projectname,                     'type' => $type                 )             )         ;         $mailer->send($message);     } } 

my tempalte new_entity.html.twig

{{ creator }} created new  {{ type }}. {{type }} name {{ name }} 

but don't work. error message.

variable "creator" not exist in mybundle::email:new_entity.html.twig @ line 1 

how solve problem. 1 me. sorry english not well.

you don't sending parameters twig (render function), there fix:

$this->container->get('templating')                     ->render('mybundle:email:new_entity.html.twig', array(                     'creator' => $creator,                     'name' => $projectname,                     'type' => $type                 ))  

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -