読み取りたいコントローラーの開始時に書き込まない限り、セッション データを読み取ることができません。以下の例:
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());
}
コントローラーを削除する$this->Session->write('Facebook.accessToken','This now works superb');
と、Facebook.accessToken2 は書き込まれません。