Hello all,
I have generated some code, and I have a feild called Active that the database has defined as a tinyint(1).
I want to display Yes or No rather than 1 or 0 on my gridview.
The code below gives me the following error:
PHP Notice – yii\base\ErrorException
Undefined variable: model
Note: The error line is at the bottom of the code below.
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel frontend\models\StudentsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Students';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="students-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Create Students', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'class' => 'yii\grid\ActionColumn',
//'template' => '{view} {update} {delete} {link}',
'template' => '{view}',
'buttons' => [
'view' => function ($url,$model) {
if($model->healthNotes <> ''){
return Html::a(
'<span class="glyphicon glyphicon-warning-sign"></span>',
$url);
}
else {
return '';
}
},
'link' => function ($url,$model,$key) {
return Html::a('Action', $url);
},
],
],
'studentID',
'studentTitle',
'firstName',
'secondName',
'surname',
// 'dateOfBirth',
// 'dateTimeCreated',
// 'healthNotes',
// 'schoolAttended',
'active',
[
'label'=>'Active',
'format'=>'raw',
'value' => $model->active == 0 ? 'No' : 'Yes', // <----- this bit is not working
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
</div>