/CakePHP 2.7

Class CakePlugin

CakePlugin is responsible for loading and unloading plugins. It also can retrieve plugin paths and load their bootstrap and routes files.

Package: Cake\Core
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Link: http://book.cakephp.org/2.0/en/plugins.html
Located at Cake/Core/CakePlugin.php

Method Detail

_includeFilesource protected static

_includeFile( string $file , boolean $ignoreMissing false )

Include file, ignoring include error if needed if file is missing


string $file
File to include
boolean $ignoreMissing optional false
Whether to ignore include error for missing files



bootstrapsource public static

bootstrap( string $plugin )

Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration


string $plugin
name of the plugin




CakePlugin::load() for examples of bootstrap configuration

loadsource public static

load( string|array $plugin , array $config array() )

Loads a plugin and optionally loads bootstrapping, routing files or loads an initialization function



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

        'DebugKit' => array('routes' => true),
        ), 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.


string|array $plugin
name of the plugin to be loaded in CamelCase format or array or plugins to load
array $config optional array()
configuration options for the plugin


if the folder for the plugin to be loaded is not found

loadAllsource public static

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:

        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:

  'ignoreMissing' => true,
  'bootstrap' => true,
  'routes' => true,

The ignoreMissing option will do additional file_exists() calls but is simpler to use.


array $options optional array()
Options list. See CakePlugin::load() for valid options.

loadedsource public static

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


string $plugin optional null
Plugin name to check.


boolean true if $plugin is already loaded. If $plugin is null, returns a list of plugins that have been loaded

pathsource public static

path( string $plugin )

Returns the filesystem path for a plugin


string $plugin
name of the plugin in CamelCase format


path to the plugin folder


if the folder for plugin was not found or plugin has not been loaded

routessource public static

routes( string $plugin null )

Loads the routes file for a plugin, or all plugins configured to load their respective routes file


string $plugin optional null
name of the plugin, if null will operate on all plugins having enabled the loading of routes files



unloadsource public static

unload( string $plugin null )

Forgets a loaded plugin or all of them if first parameter is null


string $plugin optional null
name of the plugin to forget

Properties summary


protected static array

Holds a list of all loaded plugins and their configuration


© 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.