Flash消息未显示,但存在于Flash Profiler中

时间:2019-06-11 16:54:54

标签: symfony twig flash-message

我对Flash消息有疑问(我正在使用symfony 3.2),

我的情况是:

用户注册,然后他将被重定向到登录页面,并显示消息:已创建帐户,请检查您的电子邮件。

但未显示任何消息,但我可以在探查器的Flash部分中看到它。

我的功能

  public function registrationAction(Request $request)
    {
    //my code
 $message = (new \Swift_Message('Hello Email'))
                ->setSubject($subject)
                ->setFrom($this->container->getParameter('mailer_user'))
                ->setTo($email)
                ->setBody(
                $this->renderView(
                    'PepsBundle:Register:registerconf.html.twig', array('id' => $Id,'confirmationToken' => $confirmationToken,'name' => $name,'lastname' => $lastname)), 'text/html');

            $this->get('mailer')->send($message);



            $this->addFlash('success', 'Account created!');
           return $this->redirectToRoute('peps_login');
        }

在我的login.twig.html

{% set flashbag_notices = app.session.flashBag('success') %}

我的分析器

enter image description here

1 个答案:

答案 0 :(得分:1)

您只是将消息数组分配给名为flashbag_notices的变量

您需要执行以下操作来呈现消息

{% for messages in app.session.flashbag.all() %}
      {% for message in messages %}
            <div>
                {{ message }}
            </div>
      {% endfor %}
{% endfor %}
相关问题