[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => [ 'POST' ], ], ], 'access' => [ 'class' => AccessControl::className(), 'rules' => [ [ 'allow' => true, 'roles' => [ '@' ], ], ], ], ]; } public function actions() { return [ 'index' => [ 'class' => Index::className(), 'columns' => [ 'name' => [ 'type' => Index::ACTION_COL, ], 'email' => [ 'type' => Index::STRING_COL ], 'status' => [ 'type' => Index::STATUS_COL, ], 'created_at' => [ 'type' => Index::DATETIME_COL, ] ], 'model' => Question::className(), 'hasLanguage' => false, 'enableMassDelete' => true, 'modelPrimaryKey' => 'id', 'defaultSort' => [ 'created_at' => 'DESC', ], 'create' => false ], 'view' => [ 'class' => View::className(), 'model' => Question::className(), 'hasAlias' => false, 'hasGallery' => false, 'languageFields' => [ ], 'fields' => [ [ 'name' => 'name', 'type' => Form::STRING, ], [ 'name' => 'email', 'type' => Form::STRING, ], [ 'name' => 'question', 'type' => Form::TEXTAREA, ], [ 'name' => 'created_at', 'type' => Form::STRING, ], ], ], 'delete' => [ 'class' => Delete::className(), ], ]; } public function findModel($id) { $model = Question::find() ->where([ 'id' => $id ]) ->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } public function deleteModel($id) { $category = Question::find() ->where( [ 'id' => $id, ] ) ->one(); return $category->delete(); } public function actionUpdate($id) { $model = $this->findModel($id); $services = Service::find()->all(); $data = ArrayHelper::map($services, 'id', 'title'); $doctors = Doctor::find()->all(); $dataDoctors = ArrayHelper::map($doctors, 'id', 'name'); $model->scenario = Question::SCENARIO_ANSWER; if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->redirect('index'); } else { return $this->render( 'update', [ 'model' => $model, 'services' => $data, 'doctors' => $dataDoctors ] ); } } }