[ 'class' => AccessControl::class, 'denyCallback' => function () { return $this->goHome(); }, 'rules' => [ [ 'allow' => true, 'roles' => [UserHelper::ROLE_SUPERVISOR], ], ], ], ]; } public function actionIndex(): string { $searchModel = new SchemaSearch(); $params = Yii::$app->request->queryParams; $dataProvider = $searchModel->search($params); return $this->render('index', [ 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, ]); } public function actionCreate() { $model = new Schema(); if ($model->load(Yii::$app->request->post())) { $model->save(); } else { if ($model->getErrors()) { Yii::$app->session->setFlash('error', json_encode($model->getErrors(), JSON_UNESCAPED_UNICODE)); } } return $this->render('create', [ 'model' => $model, ]); } public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Yii::t('schema', 'Сохранено')); return $this->redirect('index'); } else { if ($model->getErrors()) { Yii::$app->session->setFlash('error', json_encode($model->getErrors(), JSON_UNESCAPED_UNICODE)); } } return $this->render('update', [ 'model' => $model, ]); } public function actionDelete($id): Response { $model = $this->findModel($id); $message = Yii::t('schema', 'Удалена'); if ($model->delete()) { Yii::$app->session->setFlash('success', $message); } if ($model->getErrors()) { Yii::$app->session->setFlash('error', json_encode($model->getErrors(), JSON_UNESCAPED_UNICODE)); } return $this->redirect(['index']); } protected function findModel($id) { $model = Schema::find() ->where(['id' => $id]) ->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('app/error', 'The requested page does not exist.')); } } }