Home > Backend Development > PHP Tutorial > Can the output be output directly by returning in the ThinkPHP5 method? Ask for advice

Can the output be output directly by returning in the ThinkPHP5 method? Ask for advice

WBOY
Release: 2023-03-02 09:18:01
Original
2810 people have browsed it

Please tell me what the process is. TP5 directly uses return in the method, and the relevant content will be output in the interface. How to implement it?,, please give me some advice.

Note: Maybe you think the question is simple, but I really don’t know, so please, I want to know the execution process and method behind it.

Reply content:

Please tell me what the process is. TP5 directly uses return in the method, and the relevant content will be output in the interface. How to implement it?,, please give me some advice.

Note: Maybe you think the question is simple, but I really don’t know, so please, I want to know the execution process and method behind it.

I used TP3.2 before, but I also discovered this after changing to 5.x. I briefly looked at the source code.

The execution process is as follows:

  1. index.php

    <code>require __DIR__ . '/../thinkphp/start.php';</code>
    Copy after login
  2. start.php

    <code>App::run()->send();</code>
    Copy after login
  3. App.php

    <code>$type     = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
    $response = Response::create($data, $type);</code>
    Copy after login
  4. Json.php (assuming default_ajax_return is set to json)

    <code>$data = json_encode($data, $this->options['json_encode_param']);</code>
    Copy after login
  5. Respone.php

    <code>send() -> 调用$this.output(); -> 调用Json.php的output方法。</code>
    Copy after login

I haven’t seen the source code, I guess it’s to call the method, get the return value, and then output...

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template