会话,PHP不完整类 [英] Session, PHP Incomplete Class

查看:92
本文介绍了会话,PHP不完整类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用cakePHP 2.x。目前正在处理twitter OAuth, http://code.42dh.com/oauth/ 。 p>

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(),我无法读取会话,如果我做 $ this-> Session-> write('twitter_request_token',serialize($ requestToken)); $ requestToken = $ this - > Session-> read(unserialize('twitter_request_token'); 它会工作,但我会结束在其他地方的错误导致的序列化和unserialize会话。 b $ b

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不完整类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆