問題描述
我正在使用 cakePHP 2.x.目前正在做 Twitter OAuth,http://code.42dh.com/oauth/.>
I am using cakePHP 2.x . Currently doing about the twitter OAuth, http://code.42dh.com/oauth/.
function twitter_authentication()
{
//assume above coding is all correct.
$this->Session->write('twitter_request_token', ($requestToken));
$this->redirect('http://api.twitter.com/oauth/authenticate?force_login=true&oauth_token='.$requestToken->key); //I able to get $requestToken.
}
function twitter_login()
{
$requestToken = $this->Session->read('twitter_request_token');
$accessToken = $this->OAuthConsumer->getAccessToken('Twitter','https://api.twitter.com/oauth/access_token', $requestToken);
在 function_login() 中,我無法讀取會話并以 PhP Incomplete Class 告終.如果我做 $this->Session->write('twitter_request_token', serialize($requestToken));
和 $requestToken = $this->Session->read(unserialize('twitter_request_token');
它可以工作,但我會在其他地方因使用序列化和反序列化會話而導致錯誤.
At function_login(), I failed to read session and ended up with PhP Incomplete Class. If I do $this->Session->write('twitter_request_token', serialize($requestToken));
and $requestToken = $this->Session->read(unserialize('twitter_request_token');
it will work, but I will ended up error at other places which caused by using serialize and unserialize session.
推薦答案
PHP 不完整的類"意味著 PHP 沒有您正在加載的對象的類定義.
"PHP Incomplete Class" means PHP doesn't have a class definition for the object you're loading.
選項 A:在將對象寫入會話時弄清楚該對象是什么類,并確保在加載對象之前加載類的定義.
Option A: figure out what class that object is when you write it into the session and ensure that class's definition is loaded before loading the object.
選項B:在寫入之前將對象轉換為stdClass
或數組,并在加載后轉換回來.這可能比第一個選項更復雜.
Option B: convert the object to an stdClass
or array before writing it, and convert back after loading. This might be more complex than the first option.
這篇關于會話,PHP 不完整類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!