PHP Laravel Framework Establishment Bosses folder II

Source: Internet
Author: User
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.


  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.