Skip to main content

Yii Cheat Sheet

Back

 <?= Html::a( 'Cancel', Yii::$app->request->referrer , ['class'=>'btn btn-primary']); ?>

Grid View

[
  'attribute' => 'no_answered',
  'label' => '#vragen',
  'enableSorting' => false,
  'filter' => false,
  'headerOptions' => ['style' => 'width:60px;'],
  'contentOptions' => function ($model, $key, $index, $column) {
    if ( ! $model->finished )return ['style' => ""];
      $score = $model->no_questions > 0 ? round(($model->no_correct / $model->no_questions) * 100, 0) : 0;
    if ( $model->no_answered ) {
      $backgroundColor = $score < 55 ? 'lightcoral' : 'lightgreen';
    } else {
      $backgroundColor = "";
    }
     return ['style' => "background-color: $backgroundColor;"];
  },
  'format' => 'raw',
  'value' => function ($model) {
    return Html::a($model->no_answered.'/'.$model->no_questions, ['submission/update', 'id' => $model->id]);
    return $model->no_answered.'/'.$model->no_questions;
  },
],

['class' => 'yii\grid\SerialColumn'],
[
  'attribute' => 'label',
  'label' => 'Label',
  'headerOptions' => ['style' => 'width:200px;'],
  'contentOptions' => [
  'style' => 'color: #404080;'
],

 

xxx