About the return method in laravel
phpcn_u1582
phpcn_u1582 2017-05-16 16:54:48
0
3
1160

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?

phpcn_u1582
phpcn_u1582

reply all(3)
滿天的星座

In Laravel, the page is not output just because you return, the returned things need to be sent out through the Response,再通过它的sendmethod
.

淡淡烟草味

composer intasll can download half of the Internet

曾经蜡笔没有小新

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template