App::uses 'MyCustomController', 'Controller' ; will setup the class to be found under Controller package. App::uses 'MyHelper', 'MyPlugin. Class Navigation. Class App App is responsible for path management, class location and class loading.
Adding paths You can add paths to the search indexes App uses to find classes using App::build. Packages CakePHP is organized around the idea of packages, each class belongs to a package or folder where other classes reside.
Inspecting known objects You can find out which objects App knows about using App::objects 'Controller' for example to find which application controllers App knows about. Constants summary string. Indicates whether the class cache should be stored again because of an addition to it. Indicates whether the object cache should be stored again because of an addition to it. Holds the templates for each customizable package path in the application. Sets then returns the templates for each customizable package path.
Initializes the cache for App, registers a shutdown function. Returns the package name where a class was defined to be located at. Gets the path that a plugin is on. Searches through the defined plugin paths. Finds the path that a theme is on. Searches through the defined theme paths.
Example usage: App::objects 'plugin' ; returns array 'DebugKit', 'Blog', 'User' ; App::objects 'Controller' ; returns array 'PagesController', 'BlogController' ; You can also search only within a plugin's objects by using the plugin dot syntax.
If null, paths for the chosen type will be used. You can also fetch paths for a plugin:. App::path will only return the default path, and will not be able to provide any information about additional paths the autoloader is configured for. Plugins can be located with Plugin.
Ideally vendor files should be autoloaded with Composer , if you have vendor files that cannot be autoloaded or installed with Composer you will need to use require to load them. If your vendor library does not use classes, and instead provides functions, you can configure Composer to load these files at the beginning of each request using the files autoloading strategy:. If reset is set to true, all loaded plugins will be forgotten and they will be needed to be loaded again.
Changed in version 2. App::build can be used to add new package locations. This is useful when you want to add new top level packages or, sub-packages to your application:. You can find out which objects App knows about using App::objects 'Controller' for example to find which application controllers App knows about. Returns array instead of false for empty results or invalid types. Does not return core objects anymore, App::objects 'core' will return array. Plugins can be located with App as well.
Themes can be found App::themePath 'purple' ; , would give the full path to the purple theme. At first glance App::import seems complex, however in most use cases only 2 arguments are required. It is important to realize that the class subsequently needs to be initialized. This change has provided large performance gains to the framework. The method no longer looks for classes recursively, it strictly uses the values for the paths defined in App::build.
Using App::import 'Lib', 'CoreClass' ; to load core classes is no longer possible. App::import 'Core', 'CoreClass' is no longer supported, use App::uses instead and let the class autoloading do the rest. Loading Vendor files does not look recursively in the vendors folder, it will also not convert the file to underscored anymore as it did in the past. You can override almost every class in the framework, exceptions are the App and Configure classes.
Some examples to follow:. You can use App::uses to load classes in vendors directories. It follows the same conventions as loading other files:.
0コメント