2014-09-26 79 views
0

我的應用程序中的所有頁面默認都是安全的,除了主頁和登錄頁面。在我settings.yml我設置Symfony 1.4 - 重定向到主頁

login_module:   homepage 
login_action:   index 

因此,如果我訪問一個安全頁面,它重定向到homapage。

我的所有頁面的內容都通過ajax加載。因此,幾個小時後,我回到我的帳戶,然後點擊菜單上的內容加載主頁。所以我得到了2個菜單,2個頁腳。我需要重定向到主頁。

回答

0

經過很長時間用戶的會話過期,因此它將您的ajax請求重定向到登錄頁面。所以,您可以更改登錄操作的處理。在這種情況下,您可以在您的登錄操作中檢查引薦網址。

$link = $request->getReferer(); 
// if $link match with your AJAX link, you should send some custom message or flag in response of AJAX request. 
// so you can identify that user's session expired. 

// On failure detection of AJAX request, you can redirect browser to login page. 

編輯

如果您有多個Ajax請求。你可以做如下。

// under executeLogin() 
if($request->isXmlHttpRequest()) 
{ 
    echo '0'; 
    exit; 
} 

在AJAX處理程序方面,你能爲我的英語不好做類似下面

function ajaxResponseHandler(response) 
{ 
     if(response == 0) 
     { 
      window.location = <?php echo url_for("@login"); ?> 
     } 
} 

對不起。希望這可以幫助你。讓我知道它是否有效:-)