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 ...

Get Yii2 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.