Johannes N. Johannes N. - 1 year ago 82
PHP Question

Loading Vendor Files in CakePHP 2.0

I'm currently upgrading one of our projects to CakePHP 2.0. Unfortunately the "first line" of code makes problems, and I can't find a solution to that problem.

In CakePHP 1.3 I had an

App::import("Vendor", "facebook");
statement right before the
class gets defined. The referenced file is located under
(and includes itself the

I tried many different ways to include the file now in CakePHP 2.0 according to the File naming and class loading described here: File naming and class loading changes in CakePHP 2.0

I renamed the path to
, or
, and tried following methods:

App::uses("Facebook", "Vendor/Facebook");
App::uses("Facebook", "Facebook");
App::uses("Facebook", "Vendor/Facebook/Facebook.php");
App::uses("Facebook", "Vendor");

Has anyone find a way to reference a vendor file yet? Because of the lazy loading the methods above do not fire an error/warning, so it's kind of annoying to debug this...

Answer Source

Vendors cannot be loaded using App::uses() in CakePHP, this is because CakePHP cannot expect external libraries to follow the same standards regarding folder and file naming. You can still use App::import('Vendor', ...) as you did in version 1.3 of the framework.

Now, using App::import() for vendors is kind of silly, if you think about it. It is just an expensive, verbose and very silly wrapper for require_once().

In 2.0, we actually encourage people to use require or require_once for their Vendor libraries. You can get the location of the Vendor folder using App::path('Vendor') or just APP . 'Vendor' . DS.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download