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:
- The response output as required from the request (content negotiator).
- The HTTP method validation.
- Authentication.
- 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 ...
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.