CodeIgniter Facebook SDK 4与Composer [英] CodeIgniter Facebook SDK 4 with Composer

查看:174
本文介绍了CodeIgniter Facebook SDK 4与Composer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Composer在CodeIgniter上安装和运行Facebook SDK。

I'm trying to install and run the Facebook SDK on CodeIgniter using Composer.

CodeIgniter已安装并正常工作。

CodeIgniter is installed and working nicely.

通过执行以下操作添加了作曲者支持:

Composer support was added by doing the following:


  • curl -s http:// getcomposer.org/installer | php

  • touch composer.json

  • 线条到 composer.json 文件(facebook / php-sdk-v4:4.0。*

  • Ran 作曲家更新

  • curl -s http://getcomposer.org/installer | php
  • touch composer.json
  • Added the require lines to the composer.json file ("facebook/php-sdk-v4" : "4.0.*")
  • Ran composer update

都去计划了。 Composer创建了一个 / vendor 文件夹,而Facebook SDK就在那里。

All went to plan. Composer created a /vendor folder, and the Facebook SDK is there.

然后,我将Composer支持添加到CodeIgniter中将 include_once'./vendor/autoload.php'; 添加到 index.php 的顶部。

I then added Composer support to CodeIgniter by adding the line include_once './vendor/autoload.php'; to the top of index.php.

此时没有错误。

我现在打算调用SDK。我似乎无法使用任何Facebook类。看到下面的事情尝试和失败...

I'm now looking to call the SDK. I don't seem to be able to use any of the Facebook classes though. See below for things tried and failed...

var_dump(class_exists('Facebook') ); 显示 bool(false)

FacebookSession :: setDefaultApplication('app id removed','app secret removed');

out:

致命错误:在/ var / sites / *** / public_html / application / controllers / welcome中找不到类'FacebookSession'。第13行的php

还有一个更完整的例子:

And a more full example:

<?php
class Welcome extends CI_Controller {

    use Facebook\FacebookSession;
    use Facebook\FacebookRequest;
    use Facebook\GraphUser;
    use Facebook\FacebookRequestException;

    public function index()
    {           
        FacebookSession::setDefaultApplication('app id removed', 'app secret removed');

    }
}

吐出:
致命错误:欢迎不能使用Facebook\FacebookSession - 它不是第5行的/var/sites/***/public_html/application/controllers/welcome.php中的一个特征。

推荐答案

你混合了USE语句的位置。
你可以做的是在FB之外和之前声明来自FB SDK的类,而不是内部。通过在类中使用Use,你指向trait功能,应该包含在类中。

You've mixed the position of the USE statement. What you might do is to declare the classes from the FB SDK outside and before class, and not inside. By using Use inside a class you are pointing to trait functionality, which should be included into the class.

<?php
class MyClass extends MyBaseClass {
    // this is a namespaced trait inside the class
    // = extend class with trait
    use SomeWhere\Trait; 
}
?>

-

<?php
// this is the declaration of a namespaced class outside of the class    
use SomeWhere\Class; 

class MyClass extends MyBaseClass
{
    public function helloWorld()
    {  
        $c = new Class;
        // ...
    }
}
?>

-

您的代码变成:

<?php
use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;
use Facebook\FacebookRequestException;

class Welcome extends CI_Controller {

    public function index()
    {           
        FacebookSession::setDefaultApplication('app id removed', 'app secret removed');

    }
}

这篇关于CodeIgniter Facebook SDK 4与Composer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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