Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

facebook php sdk - CakePHP FacebookSession class not found issue

I'm trying use Facebook lib v4 to create a simple Facebook login.

I'm following Facebook guide and I'm stucked at begnning, CakePHP is not finding FacebookSession class, follow below the facts:

FacebookSession class path:

App/Lib/Facebook/src/Facebook

Use in Controller:

app::uses('FacebookSession', 'Facebook/src/Facebook');

I think the Issue is in this specific Facebook Lib because I'm using WideImage class and I'm applying the same logic to use the Class and is working Perfectly.

For the record I'm using PHP 5.4

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Custom paths/packages need to be registered

First of all that's not how App::uses() works. Custom paths/packages need to be registered first, please refer to CakePHP: Unable to load class from custom package

Also the Lib folder is ment to hold 1st party libraries, 3rd party libraries like the Facebook SDK should go into the Vendor folder.

See also Cookbook > CakePHP Folder Structure

Use composer or the autoloader that ships with the SDK

In case you can't/don't want to use the recommended way of including the SDK, that is by installing it using composer (make sure you read the notes in Installing CakePHP with Composer when using composer), then you have to make sure that you include the autoload.php file that ships with the SDK, which should be as simple as requiring it in your bootstrap

require_once APP . 'Vendor' . DS . 'Facebook' . DS . 'autoload.php';

From there on you should be able to use the SDK classes as shown in the docs.

use FacebookFacebookSession;

FacebookSession::setDefaultApplication('YOUR_APP_ID','YOUR_APP_SECRET');

$session = new FacebookSession('access-token');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...