2012-09-03 5 views
2

내가 읽고 싶은 컨트롤러의 시작 부분에 쓰지 않는 한 내 세션 데이터를 읽을 수 없습니다. 아래 예 : 나는 $this->Session->write('Facebook.accessToken','This now works superb');을 제거하면같은 컨트롤러에 쓰지 않는 한 캔트 읽기 cakephp 세션

public function login(){ 
$this->Session->write('Facebook.accessToken','This now works superb'); 
    //TODO: Implement check to see if logged in user has the same session user id. 
    require_once(APP . 'Vendor' . DS .'facebook.php'); 
    $facebook = new Facebook(array(
    'appId' => 'REMOVED', 
    'secret' => 'REMOVED' 
    )); 
    $user = $facebook->getUser(); 
    try { 
     $user_profile = $facebook->api('/me'); 
    } catch (FacebookApiException $e) { 
     $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>'http://www.facebook.com/REMOVED')); 
     $this->set('loginUrl',$loginUrl); 
    } 

    if(!isset($loginUrl)){ 
    // means that we are authenticated, so check for login with user id. If logged in redirect to event-list. If login failed display join form.  
     if($user = $this->User->findById($user_profile['id'])){ 
      if($this->Auth->login($user['User'])){ 
       $this->redirect('/users/dash'); 
      } 
     }else{ 
      $this->Session->write('Facebook.accessToken2',$facebook->getAccessToken()); 
      $this->redirect(array('controller'=>'users','action'=>'add')); 
      } 
    } 
} 


public function add(){ 
    debug($this->Session->read()); 
    $this->Session->write('testing','value'); 
    debug($this->Session->read()); 
    } 

컨트롤러가 Facebook.accessToken2을 쓰지 않습니다.

답변

0

컨트롤러에 세션 구성 요소가 있습니까?

$components[] = 'Session'; 
    //or 
    public $components = array('Session'); 

또한이 인증 컨트롤러 또는 다른 컨트롤러의 로그인 동작에만 해당합니까? 해당 지역의 컨트롤러에서

public $components = array('Session'); 
function beforeFilter() 
{ 
    $this->Session->write('Facebook.accessToken','This now works superb'); 
} 

: 당신의 AppController에서

+0

네, 제 'AppController'에 있습니다. 이것은 나의 유일한 로그인 액션 (그리고 현재 유일한 컨트롤러)입니다. –

+0

add() 액션을 살펴볼 필요가 있습니까? 쓰기 전에 읽으려고하기 때문에 그 상태에서 알 수없는 변수입니다. 또한 $ this-> Session-> read()에는 읽으려고하는 변수의 이름이 필요합니다. 요리 책을 보시오. – Jelmer

+0

'$ this-> Session-> read()'- "세션에서 $ name의 값을 반환합니다. $ name이 null이면 전체 세션이 반환됩니다."'login'은'add'에 리디렉션됩니다. 'login'에 설정된 데이터를 읽으려고하고 새로운 데이터를 추가 한 후 다시 읽으려고합니다. 추가는 위의 게시물에 포함되어 있습니다. –

0

function beforeFilter() 
{ 
    parent::beforeFilter(); 
} 
0

내가 디버거로 코드를 단계별로 제시하고 XDebug가 거라고 확신 코드 경로를 만들기 위해 사용할 당신 뒤를 기다리고있다.

Netbeans과 Eclipse는 debbuging step-through 기능이있는 사용자 나 다른 PHP 편집기/개발자를 위해이 작업을 수행 할 수 있습니다.

관련 문제