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

Creating a controller

Yii provides two base classes: \yii\rest\Controller and \yii\rest\ActiveController that we can extend when we are creating a new controller for RESTful web services.

Both of these classes contain the following useful common features, in execution order:

  1. The response output as required from the request (content negotiator).
  2. The HTTP method validation.
  3. Authentication.
  4. Rate limiting.

The second class \yii\rest\ActiveController adds more functionalities through ActiveRecord, such as handling user authorization and a set of already existing actions: index, view, create, update, delete, and options.

We will see that Yii provides all the necessary information to get the response status and content through the body and HTTP header.

Let's ...

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