/** * Finds the EntTest model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return EntTest the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = EntTest::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use yii\helpers\Html; use yii\grid\GridView; use app\models\Subject; use app\models\SubjectTest; use app\models\EntTest; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Мои результаты'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="user-score-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'test_id', ['attribute' => 'test_type', 'value' => function ($model) { if ($model->test_type == 0) { $subject = SubjectTest::findOne(['id' => $model->test_id]); return 'Тест по предмету ' . Subject::findOne(['id' => $subject->subject_id])->title; } else { $test = EntTest::findOne(['id' => $model->test_id]); return 'Ент тест п/в: ' . Subject::findOne(['id' => $test->subject_id])->title; } }], 'created_at:datetime', 'updated_at:datetime', 'score']]); ?> </div>