PHP Laravel framework of the establishment of the background folder two
In the previous chapters we explained how to create a background folder in the Laravel framework.
PHP Laravel Framework set up Background folder
Now let's add another piece of content. It's about the auto-loading section.
There is also a start directory in our app directory. It says:
In addition to using Composer, the Laravel class loader to
Load your controllers and models. This is useful-keeping all of
Your classes in the "global" namespace without Composer updating.
In addition to using composer, you can also use the Laravel class loader to load your controllers and models.
This is useful for allowing your class to be in the global namespace without using composer updating.
We have a code fragment here.
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 the folders we often use, controllers, commands. Model, database Seed
The contents of these folders can be automatically loaded into the global namespace.
But there's one more thing I'm commenting on. What is the purpose of this content?
is to let us controllers the controller in the admin in the directory also has the global namespace. So that we can go straight through the routing table.
The name of our controller came to receive.
I tested it, did it, and no longer needed compoer dumpautoload
But there is still a problem, if there is a controller in the Admin folder and the outside name is the same what to do?
I also did an experiment, and finally found that it would only choose one of them, as to which one to choose, just look at the order of loading above us.
If it is
App_path (). ' /controllers ',
App_path (). ' /controllers/admin ',
Then the external controller is valid, otherwise, the controller inside the Admin folder is valid.
The combination was written so much before. In fact, the most insurance, also tall on the way is to use the name space.
But it would be a little more complicated to write ... Small projects can take our approach. Big deal, don't let these controllers conflict.
There's no way to control it.
Do one thing at a time,and does well.
Best Wishes.