【问题标题】:Call to a member function set_userdata() on a non-object, Codeigniter OAuth2在非对象 Codeigniter OAuth2 上调用成员函数 set_userdata()
【发布时间】:2013-04-25 04:04:26
【问题描述】:

我正在尝试使用philsturgeon's OATH2 spark for CodeIgniter 对使用 Facebook 的用户进行身份验证。我安装了 Spark 并尝试了他在 github 中提供的用法示例。

在下面的代码中,我只更改了 id 和 secret。

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

  class Auth extends CI_Controller
{
    public function session($provider)
    {
        $this->load->helper('url_helper');

        $this->load->spark('oauth2-0.4.0');

        $provider = $this->oauth2->provider($provider, array(
            'id' => 'My_ID',
            'secret' => 'MY_Secret',
        ));

        if ( ! $this->input->get('code'))
        {
            // By sending no options it'll come back here
            $provider->authorize();
        }
        else
        {
            // Howzit?
            try
            {
                $token = $provider->access($_GET['code']);

                $user = $provider->get_user_info($token);

                // Here you should use this information to A) look for a user B) help a new user sign up with existing data.
                // If you store it all in a cookie and redirect to a registration page this is crazy-simple.
                echo "<pre>Tokens: ";
                var_dump($token);

                echo "\n\nUser Info: ";
                var_dump($user);
            }

            catch (OAuth2_Exception $e)
            {
                show_error('That didnt work: '.$e);
            }

        }
    }
}

但是当我尝试使用

调用控制器时
http://localhost/tddd27/index.php/auth/session/facebook

我得到以下信息:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Auth::$session

Filename: libraries/Provider.php

Line Number: 117


Fatal error: Call to a member function set_userdata() on a non-object in

C:\xampp\htdocs\tddd27\sparks\oauth2-0.4.0\libraries\Provider.php 在第 117 行

是图书馆出了什么问题还是我做错了什么?

【问题讨论】:

    标签: php codeigniter oauth-2.0


    【解决方案1】:

    似乎会话库尚未加载。尝试在函数顶部附近添加它

    $this->load->library('session');
    

    您还可以通过将库添加到您的 application/config/autoload.php 文件来自动加载库

    【讨论】:

    • 你说得对。这就是问题
    猜你喜欢
    • 1970-01-01
    • 2015-05-01
    • 1970-01-01
    • 2011-12-23
    • 2013-08-23
    • 2012-01-09
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多