Flash 消息未显示但存在于 Flash 分析器中
Flash message is not displayed but exist in the flash profiler
我有一个关于 flash 消息的问题(我使用的是 symfony 3.2),
我的场景是:
用户注册后,他将被重定向到登录页面,并显示消息:已创建帐户,请检查您的电子邮件。
但没有显示任何消息,但我可以在分析器的闪存部分看到它。
我的函数
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') %}
我的分析器
您只是将消息数组分配给名为 flashbag_notices
的变量
您需要像这样来呈现消息
{% for messages in app.session.flashbag.all() %}
{% for message in messages %}
<div>
{{ message }}
</div>
{% endfor %}
{% endfor %}
我有一个关于 flash 消息的问题(我使用的是 symfony 3.2),
我的场景是:
用户注册后,他将被重定向到登录页面,并显示消息:已创建帐户,请检查您的电子邮件。
但没有显示任何消息,但我可以在分析器的闪存部分看到它。
我的函数
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') %}
我的分析器
您只是将消息数组分配给名为 flashbag_notices
的变量您需要像这样来呈现消息
{% for messages in app.session.flashbag.all() %}
{% for message in messages %}
<div>
{{ message }}
</div>
{% endfor %}
{% endfor %}