问题
I am using the Facebook SDK For PHP. I added the facebook php SDk in the yii app protected/extension folder and imported it in config/main.php as follow.
'import' => array(
'application.extensions.facebook.*',
),
my problem is that the app is not finding the classes in the sdk when i create the object as follows:
$session = new FacebookSession($access_token);
it is giving error as follow:
Fatal error: Class 'FacebookSession' not found ....
if I try using include_once()
or require_once()
then it is giving error as below:
Fatal error: Cannot redeclare class Facebook\FacebookSession in D:\localhost\protected\extensions\facebook\FacebookSession.php on line 36
What is going wrong?
回答1:
Solved this by adding
set_include_path(Yii::app()->baseUrl . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'facebook');
require_once (Yii::app()->baseUrl . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'facebook' . DIRECTORY_SEPARATOR . 'autoload.php');
require_once (Yii::app()->baseUrl . DIRECTORY_SEPARATOR . 'protected' . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'facebook' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'Facebook' . DIRECTORY_SEPARATOR . 'FacebookSession.php');
and for creating object
$session = new Facebook\FacebookSession($access_token);
回答2:
Nitin Just Copy the zip file of your extnsion into your protected/extension directory and then extract that zip file to get .php file, try this..
来源:https://stackoverflow.com/questions/27499982/yii-import-extension-not-finding-class