Methods for lite files in thinkphp3.2 to replace a frame entry file or to apply a portal file

Source: Internet
Author: User
Tags constant definition php file php definition require

The example in this article describes how the lite file in thinkphp3.2 replaces the frame entry file or the application portal file. Share to everyone for your reference. The specific analysis is as follows:

Version 3.2 supports the generation of lite files based on the current operating environment, which can be used to replace the framework's entry files or application entry files to improve operational efficiency.

Our proposal is to generate lite files when debugging mode is turned off in a production environment.

Note that the SAE platform currently does not support the direct generation of lite files.

Generating Lite Files

To generate a lite file, you need to add a constant definition to the entry file:

The code is as follows:

Define (' Build_lite_file ', true);

By default, a lite.php file is generated under the runtime directory after it is run again.

If you need to modify the location or name of the Lite file, you can add the following configuration to the application configuration file:

The code is as follows:

' Runtime_lite_file ' => app_path. ' lite.php '

When configured, the generated Lite file location is App_path. ' lite.php '.

The compiled file content of the Lite file is the system default, and if you want to change or add other compiled files, you can define the compiled list file externally, for example: we add the lite.php definition below the application configuration directory as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Return Array (think_path. ' common/functions.php ', Common_path. ' common/function.php ', Core_path. ' Do you '. EXT, Core_path. ' Hook '. EXT, Core_path. ' App '. EXT, Core_path. ' Dispatcher '. EXT, Core_path. ' Model '. EXT, Core_path. ' Log '. EXT, Core_path. ' Log/driver/file '. EXT, Core_path. ' Route '. EXT, Core_path. ' Controller '. EXT, Core_path. ' View '. EXT, Core_path. ' Storage '. EXT, Core_path. ' Storage/driver/file '. EXT, Core_path. ' Exception '. EXT, Behavior_path. ' Parsetemplatebehavior '. EXT, Behavior_path. ' Contentreplacebehavior '. EXT,);

All files defined in the lite.php file are included in the Lite file's compilation cache. You can also make changes to the generated lite file.

If you modify the framework files and application functions and configuration files, you need to delete the Lite file regeneration.

Because cloud platforms such as SAE do not support file writes, it is not supported to generate lite files directly.

Replace entrance

The Lite file can be used to replace a frame entry file or to apply a portal file.

Replace the frame entry file

After the Lite file is generated, you can modify the frame entry file in the original application entry file as follows:

The code is as follows:

Require './thinkphp/thinkphp.php ';

Change into:

The code is as follows:

Require './runtime/lite.php ';

After replacing the Lite file, the application compilation cache is no longer required.

Replace Application entry File

If your entry file has no other code and logic, you can also access the lite.php file directly as an application entry file. Copy the lite.php file to the same directory as the application entry file and rename it directly to index.php as normal access (the original application entry file can be backed up for use when rebuilding the Lite file).

Note: If your environment or directory location changes, and changes to the core framework and application functions, configuration and other files, you will need to regenerate the lite file.

I hope this article will help you with the PHP program design based on thinkphp framework.

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.