In my index GridView I’m trying to set the class of a button which will have a number of option based on the model. As such, I was trying to make it based on a function, but am doing something wrong as Yii reports back
Undefined variable: model
Here is the gridview code in question
[
'label'=>'Invoice',
'content' => function($model, $key) {
$content = Html::button('<i class="glyphicon glyphicon-share"></i>',
[
'id'=>'invoice-'.$model->ProjId,
'class' => function($model){
if(!empty($model->InvoiceId)){
return 'btn btn-xs done';
}else{
if($model->status->Status == 'Cancelled Order'){
return 'btn btn-xs cancelled';
}else{
return 'btn btn-xs notdone';
}
}
},
'title '=> Yii::t('app', 'Generate the Invoice for project').' '.$model->ProjNo,
//...
what I don’t get is the $model is recognized in the line above, I’m passing it in the function, yet it reports undefined?
What’s the proper way to do this? Please keep in mind I still have 3 more conditions to add to the function that is why I did use a standard php ternary operator.
Thank you.