2017-02-07 102 views
1

根據JobsController的jsonresponse()函數中的一個條件,我想註銷用戶並將它們發送到登錄頁面,並顯示一條flash消息無效的用戶。CakePHP 2.6 flash消息沒有顯示

jsonresponse($數據)

if($data['status'] == '0'){ 
    $this->Session->setFlash(__(INVALID_USERS_CREDENTIALS),'default', array('class' => 'error-flash-msg')); 
     return $this->redirect($this->Auth->logout()); 
} 

現在它被重定向到登錄頁面,但閃光燈消息沒有顯示。

Loginlayout

<div style="padding-left:12%"> 
     <?php echo $this->Session->flash(); ?> 
    </div> 

    <div class="loginbox"> 
     <?php echo $this->fetch('content');?> 
    </div> 
</body> 

什麼是這裏的問題,當我轉到登錄頁面,輸入無效的憑證,它給我提示信息。但是,在上述情況下,問題是什麼......! 任何幫助,非常感謝。謝謝。

+0

您能不能告訴我們'調試($ _ SESSION)'在'view'結果' –

+0

它什麼也沒有顯示..! – Aamir

+0

但在重定向之前,如果我在控制器中調試($ _ SESSION),它將在控制器中顯示消息數據 – Aamir

回答

1

你必須設置會話閃光燈消息之前註銷,因爲logout()破壞了會議的內容

if($data['status'] == '0'){ 
    $this->Auth->logout() 
    $this->Session->setFlash(__(INVALID_USERS_CREDENTIALS),'default', array('class' => 'error-flash-msg')); 
    return $this->redirect($this->Auth->redirectUrl()); 
} 

或者,以保持重定向URL,你做到了:

if($data['status'] == '0'){ 
    $redirectUrl = $this->Auth->logout() 
    $this->Session->setFlash(__(INVALID_USERS_CREDENTIALS),'default', array('class' => 'error-flash-msg')); 
    return $this->redirect($redirectUrl); 
}