use app\models\ExamStudent; /* @var $this yii\web\View */ /* @var $model app\models\Exams */ $this->title = $id; $this->params['breadcrumbs'][] = ['label' => 'Exams', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="exams-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php $model = Exams::findOne($id); ?> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['Message', 'MaxScore', 'NumQuestions']]); ?> <?php $result = ExamStudent::findOne(['ExamId' => $id, 'StudentId' => Yii::$app->user->identity->UserID]); if ($result) { echo '<h3>Score: ' . $result->Score . '</h3>'; } else { echo '<h2>Questions</h2> <br />'; $i = 1; $questions = ExamQuestion::findAll(['ExamId' => $id]);
/** * Finds the Exams model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Posts the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Exams::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }