简体   繁体   中英

How does CakePHP connect files in different directories?

This is probably very trivial but because I'm new I just don't get it.

I can see the notion of App::uses at the beginning of every file but how does the file know where App is?
There are no includes anywhere and to my understanding there is one autoloader somewhere in lib, does that mean that one autoloader in one file is responsible for loading all the classes (if instantiated)?

I tried reading this part of the manual but still failed to understand how it works. Also read some material on the spl_autoload_register function itself but no avail.

I'd really appreciate it if someone could help me understand how the files communicate with eachother.

Look at App::load() , it's doc block explains it:

Method to handle the automatic class loading. It will look for each class' package defined using App::uses() and with this information it will resolve the package name to a full path to load the class from. File name for each class should follow the class name. For instance, if a class is name MyCustomClass the file name should be MyCustomClass.php .

And look at the frameworks core file lib/Cake/basics.php:

spl_autoload_register(array('App', 'load'));

It registers that method as auto loader.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM