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
WBOYOriginal
2016-12-01 00:57:102801browse

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>
  2. start.php

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

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

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

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

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

Statement:
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