Php Symfony模板阵列不';行不通

Php Symfony模板阵列不';行不通,php,symfony,twig,Php,Symfony,Twig,我用Symfony。我创建了助手类SendMessage use Symfony\Component\DependencyInjection\ContainerInterface as Container; class SendMessage { private $container; public function __construct(Container $container) { $this->container = $container;

我用Symfony。我创建了助手类SendMessage

use Symfony\Component\DependencyInjection\ContainerInterface as 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);
    }
}
我的Tempalte是new_entity.html.twig

{{ creator }} created new  {{ type }}. {{type }} name is {{ name }}
但是不要工作。错误消息

Variable "creator" does not exist in MyBundle::Email:new_entity.html.twig at line 1

如何解决这个问题。谁来帮我。抱歉,我的英语不太好。

如果您不向twig(渲染功能)发送参数,则有以下修复:

$this->container->get('templating')
                    ->render('MyBundle:Email:new_entity.html.twig', array(
                    'creator' => $creator,
                    'name' => $projectName,
                    'type' => $type
                )) 

如何将参数发送到heper类中的twig?@Akim使用mi-fix。在代码中,您将参数发送到setBody函数,并且必须将其发送到get('templating')->render()函数