我正在使用FOSUSerBundle并成功覆盖了控制器,表单和视图。
但是在登录失败后我找不到设置flash消息的正确位置。
我已经尝试修改SecurityController.php中的checkAction(),但它不起作用。
设置我的Flash消息的正确位置在哪里?
非常感谢你!
答案 0 :(得分:1)
我很直接地解决了这个问题:
1。)已覆盖SecurityController并编辑了loginAction
2.)挂钩到登录过程返回非空$ error
的情况// in case the login process returns an error...
if ($error) {
$error = $error->getMessage();
// ... add the desired flash message to display
$session->getFlashBag()->add('error', 'my error message here');
}
答案 1 :(得分:0)
你不需要为它覆盖控制器。
我覆盖了login.html.twig文件,并通过以下行向用户提供错误:
{% if error %}
<div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}