Home > Article > Backend Development > Can the output be output directly by returning in the ThinkPHP5 method? Ask for advice
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.
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 to5.x
. I briefly looked at the source code.
The execution process is as follows:
index.php
<code>require __DIR__ . '/../thinkphp/start.php';</code>
start.php
<code>App::run()->send();</code>
App.php
<code>$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type'); $response = Response::create($data, $type);</code>
Json.php
(assuming default_ajax_return
is set to json
)
<code>$data = json_encode($data, $this->options['json_encode_param']);</code>
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...