[英]What is the correct way to show flash message in Zend Framework 2 Expressive
I'd like to setup flash message(slim/flash). 我想设置Flash消息(超薄/ Flash)。 I saw the reference here .
我在这里看到了参考。 I made the following middleware to register flash message.
我制作了以下中间件来注册Flash消息。
use Interop\Http\ServerMiddleware\DelegateInterface;
use Zend\Diactoros\Response\RedirectResponse;
function($request, DelegateInterface $delegate)
{
$flash = $request->getAttribute('flash');
$flash->addMessage('message', 'Hello World!');
return new RedirectResponse('/other-middleware');
}
and the question is how to get this flash message from view templates? 问题是如何从视图模板获取此Flash消息? The reference wrote here but I'm not sure where should I put this code and how to show the flash.
参考资料写在这里,但我不确定该将代码放在哪里以及如何显示闪光灯。
use Interop\Http\ServerMiddleware\DelegateInterface;
function($request, DelegateInterface $delegate)
{
$flash = $request->getAttribute('flash');
$messages = $flash->getMessages();
// ...
}
Thank you for your help. 谢谢您的帮助。
The hint is in sentence below that block of code: 提示在该代码块下方的句子中:
From there, it's a matter of providing the flash messages to your template.
从那里,只需向模板提供Flash消息即可。
You need pass $messages
to your view script in order to be able to render them. 您需要将
$messages
给您的视图脚本,以便能够呈现它们。 Something like: 就像是:
return new HtmlResponse(
$this->renderer->render(
$template,
['messages' => $messages]
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.