好吧,这可能很简单。我想在Yii2中的DetailView中添加循环。 示例:
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'attribute' => 'atasan',
'value' => /*I want to add looping here*/
],
],
]) ?>
我怎样才能做到这一点?谢谢您的回答 :)
从版本2.0.11开始,qazxsw poi也可以是一个匿名函数,所以:
value
请记住,这个匿名函数应该<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'attribute' => 'atasan',
'value' => function($model) {
$example = '';
foreach($model->atasan as $atasan) {
//here your stuff
$example .= 'Oh God, it looped again. ';
}
return $example; // here's returned value
}
],
],
]) ?>
一个值,而不是回声或任何东西。