O'Reilly logo

Mastering Yii by Charles R. Portwood II

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Responses

After finishing the processing of the request object, Yii2 then generates a response object, which is sent back to the client. The response contains a myriad of information, such as the HTTP status code, response body, and headers. In Yii2, the response object is implemented by yii\web\Response, which is represented by the response application component. In this section, we'll explore how to work with responses.

Setting status codes

In most cases, Yii2 is perfectly capable of setting the appropriate response code back to the end user; however, there may be situations that require us to explicitly define the HTTP response code for our application. To modify the HTTP status code within our application, we simply need to set yii\web\Response::$statusCode ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required