public function actionCreate() { $author = $this->_checkAuth(); $json = file_get_contents('php://input'); $data = CJSON::decode($json, true); switch ($_GET['model']) { case 'articles': $model = new Article(); break; default: Helper::renderJSONErorr('create is not implemented for model ' . $_GET['model']); } foreach ($data as $var => $value) { if ($model->hasAttribute($var)) { $model->{$var} = $value; } else { Helper::renderJSONErorr("Parameter {$var} is not allowed for model " . $_GET['model']); } } if ($model->hasAttribute('author')) { $model->author = $author->id; } // Try to save the model if ($model->save()) { Helper::renderJSON($model); } $msg = sprintf("Couldn't create model %s\n", $_GET['model']); foreach ($model->errors as $attribute => $attr_errors) { $msg .= "Attribute: {$attribute}\n"; foreach ($attr_errors as $attr_error) { $msg .= "- {$attr_error}\n"; } } Helper::renderJSONErorr($msg); }