thinkphp5.0 life cycle

Source: Internet
Author: User

1. Entry file
// 应用入口文件index.php// 定义项目路径define(‘APP_PATH‘, __DIR__ . ‘/../application/‘);// 加载框架引导文件require __DIR__ . ‘/../thinkphp/start.php‘;

2. Boot file

The next step is to execute the framework's boot file, which start.php is the default boot file for the system. In the boot file, the following actions are performed:

3, registration automatic loading

The system will Loader::register() invoke the method registration auto-load, and after this step, all the conforming class libraries (including Composer the third-party class libraries that depend on loading) will be loaded automatically.

4. Registration error and abnormal mechanism

Performs Error::register() registration errors and exception handling mechanisms.

During the lifetime of the entire application request, if an exception or critical error is thrown, it causes the application to end prematurely and responds to output exceptions and error messages.

5. Application initialization

The first step in performing an application is to initialize the app, including:

    • Load the application (public) configuration;
    • Load the extension configuration file ( extra_config_list defined by);
    • Load the application state configuration;
    • Load alias definition;
    • Load behavior definition;
    • Load public (function) files;
    • Registering the application namespace;
    • Load extension function file ( extra_file_list defined by);
    • Set the default time zone;
    • Loading system language packs;
6. URL Access detection
应用初始化完成后,就会进行URL的访问检测,包括PATH_INFO检测和URL后缀检测。

So, if your environment can only support URL parameter access in normal ways, you must use the

http://serverName/index.php?s=/index/index/hello&val=value

7. Route detection
    • Routing to modules/controllers/operations;
    • Route to an external redirect address;
    • Routing to the Controller method;
    • Routed to the closure function;
    • Methods for routing to classes;

Routing addresses may be affected by domain binding.

8. Distribution Request

After URL detection and route detection are complete, the router distributes the request to the corresponding routing address, which is one of the most important aspects of the application request's life cycle.

In this step, you complete the application's business logic and return the data.

It is recommended that you use the return data uniformly instead of the return echo output, and do not use exit or die interrupt execution if it is not necessary.

The direct echo output data will not be able to automatically convert the response output convenience.

Methods of the class

In addition to the methods above, the method of distributing requests to classes is supported, including:
static method: ‘blog/:id‘=>‘\org\util\Blog::read‘
Methods of the class:‘blog/:id‘=>‘\app\index\controller\[email protected]‘

9. Response output

All operation methods of the controller are return returned instead of direct output, and the method is called to Response::send output the data returned by the final application to the page or client, and is automatically converted into default_return_type the format of the parameter configuration. Therefore, the data output of the application execution only needs to return a normal PHP data.

10. End of application

In fact, after the application data response output, the application does not really end, the system will be in the application of output or interrupt after the log save write operations.

The log of the system includes the user debug output and the system auto-generated log, and unification will be written at the end of the application.

The write operation of the log is affected by the log initialization.



thinkphp5.0 life cycle

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.