php - Symfony 4 addFlash 出现在网络选项卡上,但不在页面上
问题描述
我在这里遇到的奇怪的事情。我已经从 S4 Doc 复制了所有内容,但它似乎没有按预期工作。控制器代码:
// Adding a success type message
$this->addFlash("success", "This is a success message");
// Adding a warning type message
$this->addFlash("warning", "This is a warning message");
// Adding an error type message
$this->addFlash("error", "This is an error message");
// Adding a custom type message, remember the type is totally up to you !
$this->addFlash("bat-alarm", "Gotham needs Batman");
// 2. Retrieve manually the flashbag
// Retrieve flashbag from the controller
$flashbag = $this->get('session')->getFlashBag();
// Set a flash message
$flashbag->add("other", "This is another flash message with other type");
// Render some twig view
$carList = $this->getDoctrine()->getRepository(CarProject::class)->findAll();
return $this->render('index.html.twig', array ('carList' => $carList));
index.html.twig 代码:
<div>
{% for flash_message in app.session.flashBag.get('success') %}
<div class="alert alert-success">
{{ flash_message }}
</div>
{% endfor %}
</div>
我可以看到它已加载到 Chrome DevTools Network 选项卡上,是列表中的最新响应,但它并未出现在实际页面上。 有任何想法吗?
解决方案
我的评论给出了明确的答案,以便您可以解决这个问题:您正在尝试进行 AJAX 闪烁,这在纯树枝中是不可能的。
您应该查找诸如toastr 之类的东西或使用一些 jquery 插件。
推荐阅读
- apache-spark - 如何查看在 kubernetes 中运行的 Livy 中的执行程序日志
- javascript - 获取 html 数据属性的值后,如何将唯一值传递给可迭代对象
- java - 如何等待线程池完成所有任务?
- c++ - 如何覆盖 qHash() 函数?
- node.js - 嵌套循环同步还是异步?
- node.js - 使用 firebase 函数和 express 连接到 socket.io 的问题
- android-studio - glm::rotate() 显示错误 NO MATCHING FUNCTION FOUND
- rust - Raspberry PI 4 与特定设备的蓝牙连接上的 Blurz Rust 库
- javascript - 图片未在 Vue Js Laravel 中上传
- android - 更改 Android 应用程序标题但不更改主屏幕名称