public function actionCreateProduct() { $errors = array(); $apiAttributes = array('name' => '', 'description' => '', 'price' => '', 'category' => ''); $attributes = array_intersect_key($_GET, $apiAttributes); $product = new products($attributes); if (!$product->validate()) { $errors = $product->getValidationErrors(); } if (!$errors) { $product = new products(array('name' => $_GET['name'], 'description' => $_GET['description'], 'category' => $_GET['category'], 'price' => $_GET['price'])); if (!$product->save()) { $errors[] = 'The product could not be saved'; } else { $attributes = array('id', 'name', 'created', 'modified', 'description'); $datum = $this->returnValues($product, $attributes); $datum['category_name'] = $product->category->name; $datum['category_id'] = $product->category->id; $data = array($datum); } } if ($errors) { $this->renderApi(false, null, $errors); } else { $this->renderApi(true, $data); } }