Symfony模板数组不起作用

时间:2015-05-15 10:21:47

标签: php symfony twig

我使用Symfony。我创建了Helper Class 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

如何解决这个问题。任何人都帮助我。对不起我的英语不太好。

1 个答案:

答案 0 :(得分:3)

您没有向twig(渲染功能)发送参数,还有修复:

IReportServerCredentials irsc = DBConnection.NetworkCredentials();
ReportViewer1.ServerReport.ReportServerCredentials = irsc;

List<ReportParameter> list = new List<ReportParameter>();
list.Add(new ReportParameter("ref_no", refNo));
ReportViewer1.ServerReport.SetParameters(list);
byte[] data = ReportViewer1.ServerReport.Render("pdf");
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline;filename=Manifest_Print.pdf");
Response.BinaryWrite(data);