除非我在要读取的控制器的开头写入,否则我无法读取会话数据。下面的例子:
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。