2014-05-20 33 views
0

我正在使用FOSUSerBundle併成功覆蓋了控制器,表單和視圖。Symfony2:在成功登錄後設置flash消息

但我無法找到正確的地方設置登錄失敗後的Flash消息。

我已經嘗試修改SecurityController.php中的checkAction(),但它不起作用。

哪裏是設置我的Flash消息的正確位置?

非常感謝您提前!

+1

看看[這裏](http://stackoverflow.com/a/8312188/453348 ) – tttony

+0

謝謝,tttony的鏈接。我想它是做我所需要的,但在嘗試後我得出結論,這種方法對於我所尋找的東西來說很複雜。 – squirrel

回答

1

我解決了這個問題相當直接:已覆蓋SecurityController

1)和編輯鉤入在登錄過程中返回一個不爲空$錯誤的情況下,在loginAction

2)

// 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'); 
} 
0

你不需要爲它覆蓋控制器。

我覆蓋login.html.twig文件,給用戶的錯誤與以下行:

{% if error %} 
     <div class="alert alert-danger">{{ error.messageKey|trans(error.messageData, 'security') }}</div> 
{% endif %} 
相關問題