\Cake\CoreApp

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::path('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::path('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.

Summary

Methods
Properties
Constants
className()
shortName()
path()
core()
No public properties found
No constants found
_classExistsInBase()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

className()

className(string  $class, string  $type = '', string  $suffix = '') : false|string

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

Parameters

string $class

Class name

string $type

Type of class

string $suffix

Class name suffix

Returns

false|string —

False if the class is not found or namespaced class name

shortName()

shortName(string  $class, string  $type, string  $suffix = '') : string

Returns the plugin split name of a class

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

string $class

Class name

string $type

Type of class

string $suffix

Class name suffix

Returns

string —

Plugin split name of class

path()

path(string  $type, string|null  $plugin = null) : array

Used to read information stored path

Usage:

App::path('Plugin');

Will return the configured paths for plugins. This is a simpler way to access the App.paths.plugins configure variable.

App::path('Model/Datasource', 'MyPlugin');

Will return the path for datasources under the 'MyPlugin' plugin.

Parameters

string $type

type of path

string|null $plugin

name of plugin

Returns

array

core()

core(string  $type) : array

Returns the full path to a package inside the CakePHP core

Usage:

App::core('Cache/Engine');

Will return the full path to the cache engines package.

Parameters

string $type

Package type.

Returns

array —

Full path to package

_classExistsInBase()

_classExistsInBase(string  $name, string  $namespace) : boolean

_classExistsInBase

Test isolation wrapper

Parameters

string $name

Class name.

string $namespace

Namespace.

Returns

boolean