Build a background boss folder with phpLaravel framework 2

Source: Internet
Author: User
Create a background folder in the phpLaravel framework. in the previous section, we explained how to create a background folder in the Laravel framework. create a background folder for the phpLaravel framework. now let's add another piece of content. is about automatic loading. there is also a start directory in our app directory. it writes: InadditiontousingComposer, youmayusethe php Laravel framework, background folder 2

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.


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.