CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.6 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.6
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
      • Validator
    • Network
      • Email
      • Http
    • Routing
      • Filter
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • App
  • CakePlugin
  • Configure
  • Object

Interfaces

  • ConfigReaderInterface

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
Link: http://book.cakephp.org/2.0/en/plugins.html
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Location: Cake/Core/CakePlugin.php

Properties summary

  • $_plugins protected static
    array
    Holds a list of all loaded plugins and their configuration

Method Summary

  • _includeFile() protected static
    Include file, ignoring include error if needed if file is missing
  • bootstrap() public static
    Loads the bootstrapping files for a plugin, or calls the initialization setup in the configuration
  • load() public static
    Loads a plugin and optionally loads bootstrapping, routing files or loads an initialization function
  • loadAll() public static

    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:

  • loaded() public static

    Returns true if the plugin $plugin is already loaded If plugin is null, it will return a list of all loaded plugins

  • path() public static
    Returns the filesystem path for a plugin
  • routes() public static
    Loads the routes file for a plugin, or all plugins configured to load their respective routes file
  • unload() public static
    Forgets a loaded plugin or all of them if first parameter is null

Method Detail

_includeFile() protected static ¶

_includeFile( string $file , boolean $ignoreMissing = false )

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

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

bootstrap() public static ¶

bootstrap( string $plugin )

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

Parameters
string $plugin
name of the plugin
Returns
mixed
See
CakePlugin::load() for examples of bootstrap configuration

load() public static ¶

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.

Parameters
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
Throws
MissingPluginException
if the folder for the plugin to be loaded is not found

loadAll() 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:

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.

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

loaded() 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

Parameters
string $plugin optional null
Plugin name to check.
Returns
mixed

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


path() public static ¶

path( string $plugin )

Returns the filesystem path for a plugin

Parameters
string $plugin
name of the plugin in CamelCase format
Returns
string
path to the plugin folder
Throws
MissingPluginException
if the folder for plugin was not found or plugin has not been loaded

routes() public static ¶

routes( string $plugin = null )

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

Parameters
string $plugin optional null

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

Returns
boolean

unload() public static ¶

unload( string $plugin = null )

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

Parameters
string $plugin optional null
name of the plugin to forget

Properties detail

$_plugins ¶

protected static array

Holds a list of all loaded plugins and their configuration

array()
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs