PHP Laravel Framework for the establishment of the background folder two

Source: Internet
Author: User
Tags valid

In the previous chapters we explained how to create a background folder in the Laravel framework.

PHP laravel Framework Setup Background folder


Now we're going to add a piece of content. It's about the automatic loading section.

There is also a start directory in our app directory. It reads:

In addition to using Composer, the Laravel class loader to
Load your controllers and models. This is useful to keeping all
Your classes in the "global" namespace without Composer updating.

In addition to using composer, you can also use the Laravel classloader to load your controller and model.

This is useful for your class to be in the global namespace without the use of 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 that 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 in the controllers directory the controller in admin also has the global namespace. So we can go directly to the routing table.

Our controller name came in to receive it.

I tested it, did it, and no longer needed compoer dumpautoload

But there's still a problem, what if there's a controller in the Admin folder that's the same as the outside name?

I have also done an experiment, and finally found that it will only choose one of them, as to exactly which one to choose, it depends on the order of the 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, but also tall way is to use the name space.

But it would be a little more complicated to write. Small projects can be considered in our approach. Big deal, don't let these controllers conflict.

There's no way to control it.

Do one thing in a Time,and do.

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.