Using in External Applications

Because li3 is so flexible, you can bootstrap the core framework into any application environment, and use just the features you need. First, make sure you have installed li3 properly.

To use li3 classes, simply load the class that manages libraries (lithium\core\Libraries), and register the li3 library itself, as follows:

  1. include "/path/to/classes/libraries/lithium/core/Libraries.php";
  2. lithium\core\Libraries::add('lithium');

Note that "path/to/classes" may be relative to your include path.

Integrating with CakePHP

CakePHP provides a convenient place to add this configuration: app/config/bootstrap.php. Additionally, if you’d like to intermingle li3 classes (models and controllers) with their CakePHP counterparts, you can add the following (again, to bootstrap.php):

  1. define("LITHIUM_APP_PATH", dirname(__DIR__));
  2. lithium\core\Libraries::add('app', ['bootstrap' => false]);

This correctly locates your app directory in li3’s class loader, and suppresses app‘s default bootstrap file. You may now import your namespaced app classes in your CakePHP classes, and use li3 and CakePHP models and other classes in parallel. Note that LITHIUM_APP_PATH should be defined before Libraries.php is included.

Defining data connections

If you plan on using li3’s data layer, you need to create connections.php inside LITHIUM_APP_PATH/config. If you are defining your connections dynamically, this file can be empty. By convention, however, this file is used to configure your database and web service connections. See lithium\data\Connections for more information on how to do this.