Unlike GridView , which handles a set of models, DetailView handles only one. Therefore, there is no need to use closure, since $model is the only model to display and is available as a variable.
You can definitely use the solution suggested by rkm , but there is a simpler option.
By the way, you can simplify the condition a bit, since the allowed values ββare only 0 and 1 :
'value' => $model->recurring ? 'yes' : 'no'
If you want to display the value only as a boolean, you can add a formatting suffix with a colon:
'recurring:boolean',
'format' => 'raw' is redundant here because it is just text without html.
If you want to add additional parameters, you can use this:
[ 'attribute' => 'recurring', 'format' => 'boolean',
Using formatting is a more flexible approach, as these labels will be generated depending on the language of the application installed in config.
Official Documentation:
See also this question , it is very similar to yours.
arogachev
source share