public function actionCreate($id) { if (!($category = Category::findOne($id))) { return $this->redirect(['/admin/' . $this->module->id]); } $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; if (isset($_FILES) && $this->module->settings['articleThumb']) { $model->image = UploadedFile::getInstance($model, 'image'); if ($model->image && $model->validate(['image'])) { $model->image = Image::upload($model->image, 'article'); } else { $model->image = ''; } } if ($model->save()) { $this->flash('success', Yii::t('easyii/article', 'Article created')); return $this->redirect(['/admin/' . $this->module->id . '/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]); } }
public function actionDelete($id) { if ($model = Category::findOne($id)) { $model->delete(); } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii/article', 'Category deleted')); }