Why in laravel, return "xxx"; will directly return xxx and output it to the current page. And return "xxxx" in php will not output anything on the page. Are they the same method? How can I use PHP's original return method in Laravel without outputting content on the page?
滿天的星座2017-05-16 16:56:48
In Laravel, the page is not output just because you return, the returned things need to be sent out through the Response
,再通过它的send
method
.
曾经蜡笔没有小新2017-05-16 16:56:48
Looking at the Laravel source code, the answer lies in the SymfonyComponentHttpFoundationResponse class
The entry file calls a $response->send() method
public function send()
{
$this->sendHeaders();
$this->sendContent();
if (function_exists('fastcgi_finish_request')) {
fastcgi_finish_request();
} elseif ('cli' !== PHP_SAPI) {
static::closeOutputBuffers(0, true);
}
return $this;
}
Then look at the sendContent() method
public function sendContent()
{
echo $this->content;
return $this;
}
I see here that echo is still used