会话,PHP 不完整类

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

问题描述

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)