public function actionEditExam($id) { $exam = Exam::findOne(['id' => $id]); $examType = \common\models\ExamType::findAll(['exam_id' => $id]); $examTypeArr = []; if (!empty($examType)) { foreach ($examType as $examTypeVal) { $examTypeArr[] = $examTypeVal['name']; } } $examSec = \common\models\ExamSection::findAll(['exam_id' => $id]); $examSecArr = []; if (!empty($examSec)) { foreach ($examSec as $examSecVal) { $examSecArr[] = $examSecVal['name']; } } $model = new \common\models\ExamForm(); $model->attributes = $exam->attributes; if ($model->load(\Yii::$app->request->post()) && $model->validate()) { $model->editExam($id); \Yii::$app->session->setFlash('success', 'Exam Added Successfully'); return $this->redirect(['/exam']); } return $this->render('edit-exam', ['model' => $model, 'examTypeArr' => $examTypeArr, 'examSecArr' => $examSecArr]); }