1
votes

Cakephp Cookbook usually talks about loading Plugins with call to Plugin::load() to in order to have plugin class files available to application layer code. Understanbly Cakephp version => 3.0 is fully composer complaint and can leverage composer autoload functionality.Why then is it necessary to have special class loading mechanism for Cakephp plugins when the same thing can be achieved with a simple use keyword declaration ?

<?php 
 //in config/boostrap.php
   Plugin::load('Migrations');

what is the difference between this two ?

  // inside another controller
    use path/to/plugin/files 
1
"... in order to have plugin class files available ..." Where in the Cookbook does it say that? - ndm
@ndm Ok it says enabling/loading.What will prevent unenabled plugin from being composer loaded ? - Cholthi Paul Ttiopic

1 Answers

1
votes

The point of Plugin::load() is to register the plugin, to load possible configuration, bootstrapping, and routing files, and, if you ask for it (using the autoload option), it can even register an autoloader for cases where you cannot use composer.

Methods like Plugin::path(), Plugin::classPath(), Plugin::configPath() etc do only work with plugins that have been registered, and some internal functionality of CakePHP relies on these methods, like loading assets, configuration, or localization files from plugins.

So even if you are using composer, you may have/want to register a plugin, in order for things to work properly.