Symfony:无法从控制器向树枝添加额外的变量

时间:2019-07-17 09:37:38

标签: php symfony variables twig

我对以下代码有疑问:

控制器

$langage = $request->request->get('langage-choisis');
$baturl = "href=\"http://localhost:8000/?keyview=".$keypreview."&order=".$numerocommande."&watch=yes"."\"";

$message = (new \Swift_Message($subject))
    ->setFrom('devdalvin@gmail.com')
    ->setTo( $destinataires)
    ->setBody(
        $this->renderView('emails/contact.html.twig', [
            'IdOrder' => $langage,
            'messagegraphist' => $messagegraphist,
            'messageinvoice' => $messageinvoice,
            'baturl'=> $baturl,
            'mailinstructions' => $mailinstructions,
            'ordrefabrication' => $ordrefabrication,
            'langage' => $langage,
        ]),
       'text/html'
    );

$mailer->send($message);

树枝模板

{% block email %}
    <p>Bonjour,
        <br/> Nos équipes ont terminées la préparation du BAT pour votre commande n°{{ IdOrder  }}.
        <br>Si votre commande comporte plusieurs articles, vous recevrez un BAT par article.
        <br>Nous soulignons que nos dates de production et d'expédition courent à date de validation du présent BAT.<br>
        {% if messagegraphiste is defined %}
            <p><b>Précision de notre service graphique : </b></p>
        <br>{{ messagegraphist  }}<br>
        {% endif %}
        <br>{{ messageinvoice | raw}} <br>
    <p><a style="color: white; padding: 20px 20px; background-color: #19692c" {{ baturl | raw}} ><b>VOIR LE BAT</b></a></p>
    <br>{{ mailinstructions | raw}}<br>
    Notre équipe vous souhaite une agréable journée.
    </p>
{{ langage }}
{% endblock %}

This th error returned

无法理解的是,如果没有此错误,我将无法添加其他变量。但是,我将$ langage作为变量'IdOrder'的值,它可以工作。但是当我想在表中添加变量时:不可能。我还尝试给'langage'赋予另一个值(例如$ orderfabrication),但在'orderfabrication'起作用时仍未定义。有人有主意吗?谢谢:)

1 个答案:

答案 0 :(得分:0)

感谢您的帮助。但是,我已经考虑过清理缓存。另外,这是我的email / contact.html.twig文件的全部。 转储还用于检查定义良好的$语言的值(已在contact.html.twig中使用$ IdOrder进行检查)。 因此,我正在尝试清洁计算机。