App
in package
App is responsible for resource location, and path management.
Adding paths
Additional paths for Templates and Plugins are configured with Configure now. See config/app.php for an
example. The App.paths.plugins
and App.paths.templates
variables are used to configure paths for plugins
and templates respectively. All class based resources should be mapped using your application's autoloader.
Inspecting loaded paths
You can inspect the currently loaded paths using App::classPath('Controller')
for example to see loaded
controller paths.
It is also possible to inspect paths for plugin classes, for instance, to get
the path to a plugin's helpers you would call App::classPath('View/Helper', 'MyPlugin')
Locating plugins
Plugins can be located with App as well. Using Plugin::path('DebugKit') for example, will give you the full path to the DebugKit plugin.
Tags
Table of Contents
Methods
- className() : string|null
- Return the class name namespaced. This method checks if the class is defined on the application/plugin, otherwise try to load from the CakePHP core
- classPath() : array<string|int, string>
- Gets the path to a class type in the application or a plugin.
- core() : array<string|int, string>
- Returns the full path to a package inside the CakePHP core
- path() : array<string|int, string>
- Used to read information stored path.
- shortName() : string
- Returns the plugin split name of a class
- _classExistsInBase() : bool
- _classExistsInBase
Methods
className()
Return the class name namespaced. This method checks if the class is defined on the application/plugin, otherwise try to load from the CakePHP core
public
static className(string $class[, string $type = '' ][, string $suffix = '' ]) : string|null
Parameters
- $class : string
-
Class name
- $type : string = ''
-
Type of class
- $suffix : string = ''
-
Class name suffix
Tags
Return values
string|null —Namespaced class name, null if the class is not found.
classPath()
Gets the path to a class type in the application or a plugin.
public
static classPath(string $type[, string|null $plugin = null ]) : array<string|int, string>
Example:
App::classPath('Model/Table');
Will return the path for tables - e.g. src/Model/Table/
.
App::classPath('Model/Table', 'My/Plugin');
Will return the plugin based path for those.
Parameters
- $type : string
-
Package type.
- $plugin : string|null = null
-
Plugin name.
Return values
array<string|int, string>core()
Returns the full path to a package inside the CakePHP core
public
static core(string $type) : array<string|int, string>
Usage:
App::core('Cache/Engine');
Will return the full path to the cache engines package.
Parameters
- $type : string
-
Package type.
Return values
array<string|int, string> —Full path to package
path()
Used to read information stored path.
public
static path(string $type[, string|null $plugin = null ]) : array<string|int, string>
The 1st character of $type argument should be lower cased and will return the
value of App.paths.$type
config.
Default types:
- plugins
- templates
- locales
Example:
App::path('plugins');
Will return the value of App.paths.plugins
config.
Deprecated: 4.0 App::path() is deprecated for class path (inside src/ directory). Use \Cake\Core\App::classPath() instead or directly the method on \Cake\Core\Plugin class.
Parameters
- $type : string
-
Type of path
- $plugin : string|null = null
-
Plugin name
Tags
Return values
array<string|int, string>shortName()
Returns the plugin split name of a class
public
static shortName(string $class, string $type[, string $suffix = '' ]) : string
Examples:
App::shortName(
'SomeVendor\SomePlugin\Controller\Component\TestComponent',
'Controller/Component',
'Component'
)
Returns: SomeVendor/SomePlugin.Test
App::shortName(
'SomeVendor\SomePlugin\Controller\Component\Subfolder\TestComponent',
'Controller/Component',
'Component'
)
Returns: SomeVendor/SomePlugin.Subfolder/Test
App::shortName(
'Cake\Controller\Component\AuthComponent',
'Controller/Component',
'Component'
)
Returns: Auth
Parameters
- $class : string
-
Class name
- $type : string
-
Type of class
- $suffix : string = ''
-
Class name suffix
Return values
string —Plugin split name of class
_classExistsInBase()
_classExistsInBase
protected
static _classExistsInBase(string $name, string $namespace) : bool
Test isolation wrapper
Parameters
- $name : string
-
Class name.
- $namespace : string
-
Namespace.