我需要在DetailView
小部件中显示进度栏。我进行了搜索,但是找到了GridView
小部件的解决方案。因此我尝试对其进行修改,但未按预期工作。
<?=DetailView::widget(
[
'model' => $model,
'attributes' =>
[
[
'attribute' => 'progress',
'label' => 'Activity Progress',
'type' => DetailView::INPUT_WIDGET,
'class' => 'yii\bootstrap\Progress',
'widgetOptions' =>
[
'percent' => 50,
'barOptions' => ['class' => 'progress-bar-info'],
'options' => ['id' => 'progBar', 'class' => 'active progress-striped']
]
]
]
]
)
?>
答案 0 :(得分:1)
您只需将列format
设置为raw
并从value
选项返回窗口小部件输出即可,如下所示,我使用了yii\bootstrap\Progress
小部件, DetailView
<?php echo DetailView::widget(
[
'model' => $model,
'attributes' =>
[
[
'attribute' => 'progress',
'label' => 'Activity Progress',
'format' => 'raw',
'value' => function ($model) {
// striped animated
return \yii\bootstrap\Progress::widget(
[
'percent' => 70,
'options' => ['class' => 'progress-success active progress-striped'],
]
);
},
],
],
]
)
?>
如果数据库中有一个名为progress
的字段,该字段以整数格式保存行的当前进度,则可以将$model->progress
传递给{{ 1}}小部件,例如percent
。