在另一个函数中使用模板

时间:2012-08-17 10:56:39

标签: symfony

我创建了一个函数文件名为

<?php

use Ens\NewBundle\Controller\Services\MyMailers as MyMailers;

    function NotificationOnSignUp($z)
    {
        $x=new MyMailers;
    $x->setToloc($z['to']);
    $x->setFromloc('ucerturohit@gmail.com');
    $x->setSubject('Wonderful world');
    $x->setBody('Hello world');

    $z=$x->mail();
      if($z==1)
       $name='success';
      else
       $name='failed';

        return $this->render('EnsNewBundle:Email:ind.html.twig',array('name'=>$name));
//   return $z;  

}

此文件不在控制器中,但我想在此文件中呈现我的twig文件,或者我想将此twig文件设置为邮件正文。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

创建a service,将templating服务注入其中并使用它来呈现模板。

相关问题