【发布时间】:2018-06-15 18:33:45
【问题描述】:
我正在尝试从 ContactAction 设置 Flash 消息,然后在主页上重定向,但在其上,我看不到我的 Flash 消息,也许我的会话已重置?我可以帮忙吗,我是 Symfony 的初学者。
同时包含索引和联系功能的CoreController:
<?php
namespace OC\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class CoreController extends Controller
{
public function indexAction()
{
$ServiceAdverts = $this->container->get('oc_core.listAdverts');
$adList = $ServiceAdverts->getListAdverts();
return $this->render("OCCoreBundle:Core:index.html.twig", array(
'listAdverts' => $adList
));
}
public function contactAction()
{
$this->addFlash('info', 'Contact page not ready yet !');
return $this->redirectToRoute('oc_core_homepage');
}
}
树枝模板(主页):
{% block body %}
<div>
Messages flash :
{% for msg in app.session.flashBag.get('info') %}
<div class="alert alert-success">
{{ msg }}
</div>
{% endfor %}
</div>
<h2>Liste des annonces</h2>
<ul>
{% for advert in listAdverts %}
<li>
<a href="{{ path('oc_platform_view', {'id': advert.id}) }}">
{{ advert.title }}
</a>
par {{ advert.author }},
le {{ advert.date|date('d/m/Y') }}
</li>
{% else %}
<li>Pas (encore !) d'annonces</li>
{% endfor %}
</ul>
<a href="{{ path('oc_core_contact') }}">Contact</a>
{% endblock %}
【问题讨论】:
-
我刚刚测试了它,对我来说,你的代码有效。你有什么错误吗?
-
@DanCostinel no :/ 那么可能是什么问题?
-
您是否发布了主页树枝模板的完整代码?
-
完成,现在可以看到了。希望你能找到解决方案:/
-
那么显然你还有一个问题,因为我没有项目源代码,所以我无法告诉你任何事情。
标签: symfony session flash-message