public function actionEdit($id) { $model = Menus::findOne($id); if ($model === null) { $this->flash('error', Yii::t('easyii', 'Not found')); return $this->redirect(['/admin/' . $this->module->id]); } 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 { if (isset($_FILES) && $this->module->settings['enableThumb']) { $model->image = UploadedFile::getInstance($model, 'image'); if ($model->image && $model->validate(['image'])) { $model->image = Image::upload($model->image, 'news'); } else { $model->image = $model->oldAttributes['image']; } } if ($model->save()) { $this->flash('success', Yii::t('easyii/menu', 'News updated')); } else { $this->flash('error', Yii::t('easyii', 'Update error. {0}', $model->formatErrors())); } return $this->refresh(); } } else { return $this->render('edit', ['model' => $model]); } }
public function actionDelete($id) { if ($model = Menus::findOne($id)) { $model->delete(); } else { $this->error = Yii::t('easyii', 'Not found'); } return $this->formatResponse(Yii::t('easyii/menu', 'News deleted')); }