-
Book Overview & Buying
-
Table Of Contents
Yii Project Blueprints
By :
Now that we can authenticate and work with our API, we can work on implementing the four basic CRUD actions in a RESTful manner. The RESTful actions boil down to three main HTTP request types—GET, POST, and DELETE. We'll implement each one for our users.
The first method we need to implement is our loadModel() method. This method will be loaded in our User model and will throw the appropriate errors if something goes wrong:
private function loadModel($id=NULL)
{
if ($id == NULL)
throw new CHttpException(400, 'Missing ID');
$model = User::model()->findByPk($id);
if ($model == NULL)
throw new CHttpException(400, 'User not found');
return $model;
}The first method that we'll implement is our DELETE method. Remember that, for each method, we'll be hitting a single endpoint, /api/user/index , with different HTTP request types:
The first change that we need to make is to our accessRules. We want only administrators to have...
Change the font size
Change margin width
Change background colour