How to use Facebook PHP SDK with Zend Framework 2

自闭症网瘾萝莉.ら 提交于 2019-12-10 11:36:24

问题


I want to be able to use the Facebook PHP SDK with the new ZEND Framework 2 platform. How to do it?

Zend Framework 2 is quite different as previous version ZF1.

When I try the standard PHP in the main application controller IndexController':

require_once("facebook.php");

class IndexController extends AbstractActionController
{

    public $facebook;

    public function  __construct() {

        $this->facebook = new Facebook(array(
                'appId'  => 'appId',
                'secret' => 'secret_key'
        ));

    }

    /*
    ...
    */

}

I get following error: Fatal error: Cannot redeclare class Facebook in /../module/Application/src/Application/Controller/Facebook.php on line 160


回答1:


I can't help you specifically on the difference between ZF1 & ZF2 but a simple search in google gave me this result, I think because ZF autoloads classes and you tried to require it again they are in conflict.




回答2:


According to that error message the problem is that you now have two classes called Facebook in that namespace. Try ensuring you only have one class called Facebook.




回答3:


I had the same problem when I needed to include the Facebook SDK in a ZF2 application.

You don't need to use any additional modules for FB SDK integration. The trick is to include the facebook library with ClassMapAutoloader, e.g.:

array(
    'Facebook' => 'vendor/FB/facebook.php',
)

Detailed instructions are here



来源:https://stackoverflow.com/questions/13030026/how-to-use-facebook-php-sdk-with-zend-framework-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!