I always struggle to include third party library files in my Cake project as they very often do not adhere to any coding standard such as PSR0.

Where to put the files?

Third party files should always go into your Vendor folder inside your project, if they are not loaded using Composer.

How to load them?

Update, 6 March 2015
One of the core developers for the framework advices against using the technique I describe in this post. So I am amending the post to reflect this.

Using require_once

In order to include third party library files, you can use require_once(). The only complication is getting the correct path to use.

// To load app/Vendor/DavesLibrary/DavesClass.php
require_once(APP . 'Vendor' . DS . 'DavesLibrary' . DS . 'DavesClass.php');

The older way

Usually you will want to use the App class to load your third party classes into your application using App::import(). The parameters of this in the api do not match the usage, which apparently is for backwards compatibility.

The App class in the cookbook.

The code will look like the following.

App::import('Vendor', 'TheNameOfMyClass', array('file' => 'DavesLibrary'.DS.'DavesClass.php'));

// DavesLibrary/DavesClass.php
class TheNameOfMyClass { }

// Importing a Vendor library from a plugin? No problem, use plugin.notation
App::import('Vendor', 'DavesPlugin.TheNameOfMyClass', array('file' => 'DavesLibrary'.DS.'DavesClass.php'));


Make a brew!