2011-08-08 11 views
0

私は管理者/ユーザのログインにCakePHP 1.3の最新バージョンを使用しています。CakePHPセッション、最初のリフレッシュ時に表示されない

Authを使用してログインしようとすると、私はSESSIONに情報を表示していませんが、ページをもう一度更新すると、すべての情報がSessionに送信されます。

これは何故起こりますか?

コードがapp_controller.phpファイル

function beforeFilter() 
{ 
    $this->Auth->autoRedirect = false; 
    $this->Auth->fields = array('username' => 'email_address', 'password' => 'password'); 
    $this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login'); 
    $this->Auth->userScope = array('User.status' => '1','User.paymentstatus' => '0'); 
    if($this->Auth->User()) 
    { 
     if($this->Session->read('Auth.User.user_type') == 3) { 
      $this->layout = 'admin'; 
      $this->Auth->loginRedirect = array('controller' => 'admins', 'action' => 'welcome'); 
     } 
     else 
     { 
      $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'display', 'home'); 
     } 
    } 
} 

function beforeRender(){ 
    $this->set('auth', $this->Auth->user()); 
    header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); // // HTTP/1.1 
    header("Pragma: no-cache"); 
    header("Expires: Mon, 17 Dec 2007 00:00:00 GMT"); // Date in the past 
} 

からここにある最古の応答がいただければ幸いです。

ありがとうございます!

+0

とビューであなたがログイン成功後にリダイレクトしていることをアクセスすることができますか?同じリクエストが設定されている間はセッションデータにアクセスすることはできません( '$ _SESSION')。 – deizel

+0

はい私は、初めてログインしたときに、ようこそページにリダイレクトしていますが、ユーザーが初めてログインしたときにリダイレクトしていないときに、再度ページをリフレッシュすると、リダイレクト先になります.. –

+0

あなたはログイン/リダイレクトに行っているアクションを投稿することができますので、より詳しく見ることができます。 – deizel

答えて

1
function beforeFilter(){ 
    parent::beforeFilter(); 
    $this->Auth->autoRedirect = false; 
    $this->Auth->fields = array('username' => 'email_address', 'password' => 'password'); 
    $this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login'); 
    $this->Auth->userScope = array('User.status' => '1','User.paymentstatus' => '0'); 
    if($this->Auth->user() && $this->Auth->user('user_type') == 3) 
     $this->layout = 'admin'; 
} 
function login(){ 
    if($this->Auth->user()){ 
    if($this->Auth->user('user_type') == 3) { 
     $this->redirect(array('controller' => 'admins', 'action' => 'welcome')); 
    } else { 
     $this->redirect(array('controller' => 'pages', 'action' => 'display', 'home')); 
    } 
    } 
} 

あなたはbeforeRenderに認証を設定する必要はありません、あなたはまだ$this->Session->read('Auth.User');

+0

あなたは '$ this-> Auth-> autoRedirect = false'を設定しているので、簡単に' UsersController :: login() 'アクションでリダイレクトする必要があります([cookbook](http:// book .cakephp.org/view/1274/autoRedirect))。通常は '$ this-> redirect($ this-> Auth-> redirect());'を入れますが、あなたのリダイレクトURLが異なるので上記のコードはあなたのニーズを満たすはずです。 – deizel

関連する問題