CakePlugin is responsible for loading and unloading plugins. It also can retrieve plugin paths and load their bootstrap and routes files.
_includeFile( string $file , boolean $ignoreMissing false )
Include file, ignoring include error if needed if file is missing
$file
$ignoreMissing
optional false mixed
bootstrap( string $plugin )
Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration
$plugin
mixed
load( string|array $plugin , array $config array() )
Loads a plugin and optionally loads bootstrapping, routing files or loads an initialization function
Examples:
CakePlugin::load('DebugKit')
Will load the DebugKit plugin and will not load any bootstrap nor route files
CakePlugin::load('DebugKit', array('bootstrap' => true, 'routes' => true))
will load the bootstrap.php and routes.php files
CakePlugin::load('DebugKit', array('bootstrap' => false, 'routes' => true))
will load routes.php file but not bootstrap.php
CakePlugin::load('DebugKit', array('bootstrap' => array('config1', 'config2')))
will load config1.php and config2.php files
CakePlugin::load('DebugKit', array('bootstrap' => 'aCallableMethod'))
will run the aCallableMethod function to initialize it
Bootstrap initialization functions can be expressed as a PHP callback type, including closures. Callbacks will receive two parameters (plugin name, plugin configuration)
It is also possible to load multiple plugins at once. Examples:
CakePlugin::load(array('DebugKit', 'ApiGenerator'))
will load the DebugKit and ApiGenerator plugins
CakePlugin::load(array('DebugKit', 'ApiGenerator'), array('bootstrap' => true))
will load bootstrap file for both plugins
CakePlugin::load(array( 'DebugKit' => array('routes' => true), 'ApiGenerator' ), array('bootstrap' => true))
Will only load the bootstrap for ApiGenerator and only the routes for DebugKit. By using the path
option you can specify an absolute path to the plugin. Make sure that the path is slash terminated or your plugin will not be located properly.
$plugin
$config
optional array() MissingPluginException
loadAll( array $options array() )
Will load all the plugins located in the configured plugins folders If passed an options array, it will be used as a common default for all plugins to be loaded It is possible to set specific defaults for each plugins in the options array. Examples:
CakePlugin::loadAll(array( array('bootstrap' => true), 'DebugKit' => array('routes' => true, 'bootstrap' => false), ))
The above example will load the bootstrap file for all plugins, but for DebugKit it will only load the routes file and will not look for any bootstrap script. If you are loading many plugins that inconsistently support routes/bootstrap files, instead of detailing each plugin you can use the ignoreMissing
option:
CakePlugin::loadAll(array( 'ignoreMissing' => true, 'bootstrap' => true, 'routes' => true, ));
The ignoreMissing option will do additional file_exists() calls but is simpler to use.
$options
optional array() loaded( string $plugin null )
Returns true if the plugin $plugin is already loaded If plugin is null, it will return a list of all loaded plugins
$plugin
optional null mixed
path( string $plugin )
Returns the filesystem path for a plugin
$plugin
string
MissingPluginException
routes( string $plugin null )
Loads the routes file for a plugin, or all plugins configured to load their respective routes file
$plugin
optional null boolean
unload( string $plugin null )
Forgets a loaded plugin or all of them if first parameter is null
$plugin
optional null
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/2.7/class-CakePlugin.html