简体   繁体   中英

Facebook class not found in CakePHP 2

Downloaded the Facebook PHP SDK using composer in CakePHP 2 and included the folder location in AppController :

class AppController extends Controller {

    public function beforeFilter() {
        App::import('Vendor', 'Facebook/autoload.php');

        $this->Facebook = new Facebook(array(
            'appId'     =>  'myappid',
            'secret'    =>  'mysecretkey',
            'default_graph_version' => 'v2.2',
        ));
    }

Error:

 Fatal error: Class 'Facebook' not found in C:\wamp\www\rent\app\Controller\AppController.php on line 38 –

I have checked if the CURL extension is enabled in wampp server, and I confirm it is.

The correct syntax to load app/Vendor/Facebook/autoload.php is:

App::import('Vendor', 'autoload', array('file' => 'Facebook/autoload.php'));

See the Cookbook for more information: Loading Vendor Files

However, you have mentioned you have installed the package with composer . If this is the case, you only have to include the line:

require APP . 'Vendor/autoload.php';

in your app/Config/bootstrap.conf file, and whatever you install with composer will be automatically loaded. No need to load each individual class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM