내가 읽고 싶은 컨트롤러의 시작 부분에 쓰지 않는 한 내 세션 데이터를 읽을 수 없습니다. 아래 예 : 나는 $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을 쓰지 않습니다.
네, 제 'AppController'에 있습니다. 이것은 나의 유일한 로그인 액션 (그리고 현재 유일한 컨트롤러)입니다. –
add() 액션을 살펴볼 필요가 있습니까? 쓰기 전에 읽으려고하기 때문에 그 상태에서 알 수없는 변수입니다. 또한 $ this-> Session-> read()에는 읽으려고하는 변수의 이름이 필요합니다. 요리 책을 보시오. – Jelmer
'$ this-> Session-> read()'- "세션에서 $ name의 값을 반환합니다. $ name이 null이면 전체 세션이 반환됩니다."'login'은'add'에 리디렉션됩니다. 'login'에 설정된 데이터를 읽으려고하고 새로운 데이터를 추가 한 후 다시 읽으려고합니다. 추가는 위의 게시물에 포함되어 있습니다. –