Changing value of an attribute in DetailView widget

霸气de小男生 提交于 2019-11-27 15:11:24

Try

'value' => $model->recurring == 1 ? 'yes' : 'no'
arogachev

Unlike GridView which processes a set of models, DetailView processes just one. So there is no need for using closure since $model is the only one model for display and available in view as variable.

You can definitely use solution suggested by rkm, but there is more simple option.

By the way you can simplify condition a bit since the allowed values are only 0 and 1:

'value' => $model->recurring ? 'yes' : 'no'

If you only want to display value as boolean, you can add formatter suffix with colon:

'recurring:boolean',

'format' => 'raw' is redundant here because it's just text without html.

If you want add more options, you can use this:

[
    'attribute' => 'recurring',
    'format' => 'boolean',    
    // Other options
],

Using formatter is more flexible approach because these labels will be generated depending on application language set in config.

Official documentation:

See also this question, it's quite similar to yours.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!