mrdaliri
mrdaliri

Reputation: 7338

how to use composer packages in CakePHP plugin

I'm going to develop a CakePHP 2 plugin which relay on a composer package. That package is installed in "APP/Vendor" directory. And my plugin is in "APP/Plugin".

Shall I put App::import('Vendor', array('file' => 'autoload')); in my plugin files?

Upvotes: 2

Views: 1803

Answers (1)

Inigo Flores
Inigo Flores

Reputation: 4469

If the package in app/Vendor was installed with composer, automatic loading should be taken care by

require APP . 'Vendor/autoload.php';

in your app/Config/bootstrap.php.

However, if it was downloaded and copied over to /app/Vendor, you should manually import it:

App::import('Vendor', 'packageFolder/filename');

The same applies to Plugins. If you declare your dependencies in your Plugin/PluginName/composer.json, within "require":, these will be installed together with your plugin, and added to app/Vendor/autoload.php, so no need to manually import.

If the package was downloaded to /app/Plugin/PluginName/Vendor/, you will have to load it via

App::import('Vendor', 'PluginName.packageFolder/filename');

Upvotes: 5

Related Questions