O'Reilly logo

Yii2 By Example by Fabrizio Caldarelli

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

Other forms of export – RSS

Yii allows us to create a custom format response to output data. The response format can be changed based on the Accept HTTP header sent by the client or done programmatically. When Yii receives a request, it searches for an available response formatter based on the Accept HTTP header value and finally calls the format ($response) method of the response formatter found.

Therefore, there are three steps to create custom responses:

  1. Implementing the yii\web\ResponseFormatterInterface interface.
  2. Adding a new custom formatter response property in the configuration file.
  3. Extending the behaviors() method of the controller to handle specific Accept HTTP header values.

The first step requires us to implement the yii\web\ResponseFormatterInterface ...

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