DetailView 中的 Yii2 进度条
Yii2 Progress Bar in a DetailView
我需要在 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']
]
]
]
]
)
?>
您只需将 format
列设置为 raw
和 return value
选项的小部件输出,如下所示,我使用了 [= DetailView
中的 14=] 小部件
<?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
传递给 percent
选项yii\bootstrap\Progress
像 "percent"=>$model->progress
.
这样的小部件
我需要在 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']
]
]
]
]
)
?>
您只需将 format
列设置为 raw
和 return value
选项的小部件输出,如下所示,我使用了 [= 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
传递给 percent
选项yii\bootstrap\Progress
像 "percent"=>$model->progress
.