The previous chapter explains how to create a background folder in the Laravel framework.
Php Laravel framework-Background Folder creation
Now let's add another piece of content, which is about automatic loading.
There is also a start directory in our app Directory, which writes as follows:
In addition to using Composer, you may use the Laravel class loader
Load your controllers and models. This is useful for keeping all
Your classes in the "global" namespace without Composer updating.
In addition to using Composer, you can also use Laravel classloaders to load your controllers and models.
This is useful for keeping your class in a global namespace without using Composer updating.
Here we have a code fragment
ClassLoader: addDirectories (array (
App_path (). '/commands ',
App_path (). '/controllers ',
// App_path (). '/controllers/admin ',
App_path (). '/models ',
App_path (). '/database/seeds ',
));
Yes, very familiar. These folders are commonly used folders, controllers, commands, models, and database seeds.
The contents in these folders can be automatically loaded into the global namespace.
But I have added a comment. What is the purpose of this content ..
The Controller in admin in the controllers directory also has a global namespace, so that we can directly
Our controller name is used for receiving.
I tested it and it succeeded, instead of using compoer dumpautoload.
But there is still a problem. What if there is a controller in the admin folder with the same name as the name outside?
I did the same experiment and finally found that it only chooses one of them. As for which one is selected, it depends on the loading sequence above.
If yes
App_path (). '/controllers ',
App_path (). '/controllers/admin ',
The external controller is valid. Otherwise, the Controller in the admin folder is valid.
In fact, the most secure and advanced method is to use namespace.
But it will be a little more complicated to write... small projects can consider our approach. It's a big deal to pay attention, don't let these controllers conflict with each other.
No way to control it, right.
Do one thing at a time, and do well.
Best Wishes.