我正在使用FOSUserBundle來管理我的網站用戶。我的目標是使登錄表單顯示在基於boostrap框架的模式窗口中。下來是我的模態窗口基於FOSUserBundle和引導登錄模式窗口不正確工作
<div class="modal hide" data-backdrop="static" id="login">
<div class="modal-header"> <a class="close" data-dismiss="modal">×</a>
<h3>Connexion</h3>
</div>
<div class="modal-body" >
</div>
</div>
<a class="btn btn-primary" data-toggle="modal" data-target="#login"
href="{{ path('fos_user_security_login') }}">Sign in</a>
代碼此代碼工作得很好,如果用戶沒有犯任何錯誤,同時entring他的用戶名和他的密碼。如果有錯誤,symfony2將我直接重定向到/login
頁面,該頁面是捆綁包FOSUserBundle提供的極簡主義頁面頁面。
爲了擺脫這個問題,我的想法在於收聽javascript事件,它將再次顯示窗口。這是通過window.hashchange事件完成的。對於所提出的代碼是:
<script type="text/javascript" src="{{ asset('jquery/1.9.1/jquery.ba-hashchange.min.js')}}"></script>
<script>
$(function() {
// Bind the event.
$(window).hashchange(function() {
// Alerts every time the hash changes!
alert(location.hash);
if(location.hash === "#login"){
$('#login').modal();
}
});
// Trigger the event (useful on page load).
$(window).hashchange();
});
</script>
這是偉大的:throught這段代碼中,成爲能夠顯示登錄模式窗口,如果我去這個網址/#login
。
但是,問題仍然沒有解決,因爲symfony中存在路由問題。 我不得不重寫所有的包來在FOSUserBundle的控制器中進行重定向。
任何想法?