Dail
Dail

Reputation: 4608

Error Importing Vendor class in CakePhp

I have:

App/Vendor/Facebook
App/Vendor/Facebook/facebook.php

in App/Controller/AppController.php I used:

App::uses('facebook', 'Vendor/Facebook');

Then the AppController class is:

class AppController extends Controller {

    public $fb;

    public function beforeFilter() {
        $fb = new Facebook();   
    }   

}

Here is the error I got:

Fatal error: Class 'Facebook' not found in /home/users/example.com/www/app/Controller/AppController.php on line 42

How is this possible? What is wrong?

Thanks!

Upvotes: 0

Views: 9211

Answers (2)

Idealmind
Idealmind

Reputation: 1298

This issue ocurred with me..

I did some tests do know what was happening.

First, I renamed facebook.php to Facebook.php. This is not really necessary. It depends of your cakephp version.

So, in Cake/Core/App.php, I commented line 738 ( return (bool)include_once $mapped; ) and change to require_once $mapped.

Later, I got an error with LIB CURL, that is required to run the php facebook lib. So, I installed it:

sudo aptitude install php5-curl
sudo /etc/init.d/apache2 restart

This time, the error changed to:

Fatal error: Cannot redeclare class Facebook in (...)

Finally, I restored Cake/Core/App.php to original, and the error was solved.

Best regards

Upvotes: 0

dhofstet
dhofstet

Reputation: 9964

You have to use App::import() to import your file because it doesn't follow the CakePHP conventions. The following snippet should do the trick:

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

See also http://book.cakephp.org/2.0/en/core-utility-libraries/app.html#loading-vendor-files

Upvotes: 6

Related Questions