/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate() { if ($this->catalog) { $catalog = ucwords($this->catalog); $id = (int) Yii::app()->request->getParam("id", 0); if (!empty($id)) { $model = $catalog::fetch($id); } else { $model = new $catalog(); } $message = ""; // Сохрание полей if (isset($_POST[$catalog])) { $model->setAttributesFromArray($_POST[$catalog]); if ($model->description) { $model->description = str_replace("../../../../", Yii::app()->params["baseUrl"], $model->description); } if (!empty($_FILES[$catalog])) { foreach ($_FILES[$catalog]["name"] as $key => $field) { if (property_exists($model, $key)) { $model->{$key} = $field; } } } if ($model->saveWithRelation()) { $message = "Данные успешно сохраненны"; //$this->redirect(array('view','id'=>$model->id)); } } // Сохранение TITLE галереи if (!empty($_POST["image_submit"]) && !empty($_POST["image"])) { foreach ($_POST["image"] as $value) { if ($value["id"] > 0) { $imageModel = CatGallery::fetch($value["id"]); if ($imageModel->id > 0) { $imageModel->name = $value["name"]; $imageModel->pos = $value["pos"]; $imageModel->type = $value["type"]; $imageModel->save(); } } } $message = "Галерея успешно сохраненна"; } // Добвление картинки $addGallery = new CatGallery(); if (!empty($_POST["submit_add_gallery"]) && !empty($id)) { $addGallery->setAttributesFromArray($_POST["CatGallery"]); $addGallery->image = $_FILES["CatGallery"]["name"]["image"]; $addGallery->catalog = $model->tableName(); $addGallery->item_id = $id; $addGallery->save(); // "", false $addGallery = new CatGallery(); } if ($model->id > 0) { $listImage = CatGallery::findByAttributes(array("catalog" => $model->tableName(), "item_id" => $model->id)); } else { $listImage = array(); } $this->render('edit', array('arrayParams' => $this->arrayParams, 'form' => $model, 'catalog' => $this->catalog, 'listImage' => $listImage, 'message' => $message, 'addGallery' => $addGallery)); } }