public function actionUpdate($id) { if ($this->item->load(Yii::$app->request->post()) && $this->item->save()) { return $this->refresh(); } return $this->render('update', ['model' => $this->item]); }
public function actionCreate($id) { if (!($category = Category::findOne($id))) { return $this->redirect(['/admin/catalog']); } $model = new Item(); if ($model->load(Yii::$app->request->post())) { if (Yii::$app->request->isAjax) { Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ActiveForm::validate($model); } else { $model->category_id = $category->primaryKey; $model->data = Yii::$app->request->post('Data'); if (isset($_FILES) && $this->module->settings['itemThumb']) { $model->thumb = UploadedFile::getInstance($model, 'thumb'); if ($model->thumb && $model->validate(['thumb'])) { $model->thumb = Image::upload($model->thumb, 'catalog', $this->module->settings['itemThumbWidth'], $this->module->settings['itemThumbHeight'], $this->module->settings['itemThumbCrop']); } else { $model->thumb = ''; } } if ($model->save()) { $this->flash('success', Yii::t('easyii/catalog', 'Item created')); return $this->redirect(['/admin/catalog/items/edit/', 'id' => $model->primaryKey]); } else { $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors())); return $this->refresh(); } } } else { return $this->render('create', ['model' => $model, 'category' => $category, 'dataForm' => $this->generateForm($category->fields)]); } }