/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Values the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Values::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionSaveProduct() { $product = Products::model()->findByPk($_POST['productId']); $attributes = json_decode($_POST['attributes']); //удмлим все значения, связанные с текущим атрибутом и сам атрибут $attributes_AR = Attributes::model()->findAll("product_id=:product_id", array(':product_id' => $_POST['productId'])); foreach ($attributes_AR as $attribute) { Values::model()->deleteAll("attribute_id=:attribute_id", array(':attribute_id' => $attribute->id)); $attribute->delete(); } foreach ($attributes as $attribute) { $attribute_AR = new Attributes(); $attribute_AR->product_id = $product->id; $attribute_AR->name = $attribute->name; $res = $attribute_AR->save(); if ($res == false) { echo "false-attr"; return; } foreach ($attribute->values as $value) { $value_AR = new Values(); $value_AR->name = $value->name; $value_AR->add_price = $value->add_price; $value_AR->attribute_id = $attribute_AR->id; $res = $value_AR->save(); if ($res == false) { echo "false-value"; return; } } } $product->discount = $_POST['discount']; $product->name = $_POST['name']; $product->text = $_POST['text']; if ($_POST['photo'] != '') { $product->photo = $_POST['photo']; } $product->main_price = $_POST['main_price']; $product->sostav = $_POST['sostav']; $res = $product->update(); if ($res == false) { var_dump($product->errors); echo "false-prod"; return; } echo "true"; }