/** Товары: Редактирование товара */ public function actionUpdateproduct($id) { $this->breadcrumbs = array('Список товаров' => array('/catalog/catalog/listelement'), 'Редактирование'); $model = $this->loadModelProduct($id); $root = CatalogRubrics::getRoot(); $catalog = CMap::mergeArray(array($root->id => $root->name), $root->getFormattedDescendants($root->id)); if (isset($_POST['CatalogElements'])) { $model->attributes = $_POST['CatalogElements']; $model->imagefile = CUploadedFile::getInstance($model, 'imagefile'); if (isset($model->imagefile)) { $ext = pathinfo($model->imagefile); $model->image = $ext['extension']; } if ($model->save()) { $filepatch = '/../uploads/filestorage/catalog/elements/'; if (isset($model->imagefile) && ($modelSettings = SiteModuleSettings::model()->find('site_module_id = 4'))) { $filename = $model->id . '.' . $model->image; $model->imagefile->saveAs(YiiBase::getPathOfAlias('webroot') . $filepatch . $filename); //Обработка изображения SiteModuleSettings::model()->chgImgModel($modelSettings, 'GD', 2, $model->id); } //загрузка дополнительных картинок $files = CUploadedFile::getInstances($model, 'imagefiles'); if (!empty($files)) { foreach ($files as $file) { $modelImages = new CatalogElementsImages(); $modelImages->elements_id = $model->id; $modelImages->image_name = $model->id . '_' . md5(date('Y-m-d H:i:s') . '-' . rand()); $ext = pathinfo($file->getName()); $modelImages->image = $ext['extension']; $modelImages->save(); $uplod_file_url = YiiBase::getPathOfAlias('webroot') . $filepatch . '/' . $modelImages->image_name . '.' . $modelImages->image; $uplod_file_url = $file->saveAs($uplod_file_url); } SiteModuleSettings::model()->chgImgagesCatalogModel($model->id, 'GD'); } $this->redirect(array('updateproduct', 'id' => $model->id)); } } $this->render('formproduct', array('model' => $model, 'root' => $root, 'catalog' => $catalog)); }