2013-04-11 57 views
3

我正在使用FOSUserBundle來管理我的網站用戶。我的目標是使登錄表單顯示在基於boostrap框架的模式窗口中。下來是我的模態窗口基於FOSU​​serBundle和引導登錄模式窗口不正確工作

<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的控制器中進行重定向。

任何想法?

回答

0

您可以檢查是否登錄使用後出現錯誤:

{% if error %} 
    {# do something #} 
{% endif %} 

這意味着,你可以檢查你是否希望模態隱藏,或者如果你想顯示它 的頁面加載像這樣:

<div class="modal{% if not error %} hide{% endif %}"> 
    <!-- model window --> 
</div> 
0

我解決了重寫login.twig.html並把這個起點附近

{% if error %} 
    <script> 
     $('.modal').modal("show"); 
    </script> 
    <div>{{ error|trans }}</div> 
{% endif %} 

但即時通訊仍然缺少如何讓這種模式出現,當用戶點擊一個安全的行動 並獲得重定向鏈接他點擊,而不是包含該鏈接的頁面(即什麼進入$ request-> headers-> get儘管(「引薦」)被首先從哪裏擔保行爲是重定向)