PHP changes the order of automatic loading

Source: Internet
Author: User

Composer's pot

Since the Phper have used the composer, for the traditional loading method is not used, can be described as "received East, lost roundabouts."
Let's talk about how to change the load order to overwrite the helper function in Laravel.

1. Direct require

Open the Laravel portal file index.php, you can see require __DIR__.‘/../vendor/autoload.php‘; , for example, we overwrite the Today function
You can add a helper.php to the app directory, then overwrite,

<?phpuse Carbon\Carbon;function today(){return Carbon::today("PRC")->toDateTimeString();}

Change to a string, create a new route, test it, and find that the string is returned.

2. Using Composer-include-files

Install composer require Funkjedi/composer-include-files first
Then edit the Composer.json and add the Include_files to the extra entry.

{"extra": {"include_files": [    "app/helpers.php"    ]},}

Note that before you do, you have to put helper.php in the auto-add

"autoload": {    "files": [        "app/helpers.php"    ]}

Run composer dump, you can see in the vendor/composer/autoload_files.php, our helper.php was put to the front

PHP changes the order of automatic loading

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.