yii import extension not finding class

拜拜、爱过 提交于 2019-12-23 00:43:29

问题


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

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