Ejemplo n.º 1
0
            </div>
        </header>
        <div class="body">
            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => ['id', ['attribute' => 'skill_id', 'content' => function ($data) {
    $skillName = Skill::findOne($data->skill_id)->title;
    return $skillName ? $skillName : '<span style="color:red">Không tìm danh mục</span>';
}, 'format' => 'raw'], ['attribute' => 'question', 'content' => function ($data) {
    return Html::a($data->question, ['view', 'id' => $data->id]);
}], 'answer', ['attribute' => 'difficulty', 'content' => function ($data) {
    switch ($data->difficulty) {
        case '0':
            return '<span class="btn-success label">Dễ</span>';
            break;
        case '1':
            return '<span class="btn-warning label">Trung bình</span>';
            break;
        default:
            return '<span class="btn-danger label">Khó</span>';
            break;
    }
}, 'format' => 'raw'], ['attribute' => 'state', 'content' => function ($data) {
    return Quiz::findOne($data['id'])->state == 1 ? '<span class="label-success label label-default">Kích hoạt</span>' : '<span class="label-default label">Không kích hoạt</span>';
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete}', 'header' => 'Thao tác', 'buttons' => ['delete' => function ($url, $model) {
    return '<a class="btn btn-danger" aria-label="Delete" data-confirm="Bạn có chắc muốn xóa danh mục này?" data-method="post" data-pjax="0" href="' . $url . '"><i class="icon icon-trash icon-white"></i></a>';
}]]]]);
?>
        </div>
    </div>
</div>
Ejemplo n.º 2
0
 /**
  * Finds the Quiz model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Quiz the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Quiz::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }