php - 如何在 DetailView Yii2 中添加循环?
问题描述
好的,这可能很简单。我想在 Yii2 的 DetailView 中添加循环。
例子 :
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'attribute' => 'atasan',
'value' => /*I want to add looping here*/
],
],
]) ?>
我怎样才能做到这一点?谢谢您的回答 :)
解决方案
由于版本2.0.11 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
}
],
],
]) ?>
请记住,这个匿名函数应该return
是一个 value,而不是 echo 或任何东西。
推荐阅读
- node.js - Node-Red:将数据传递到 exec 的标准输入,而不是重新运行
- java - 如何使用流检查多个集合的字符串
- xamarin - 如果行定义中的所有行大小相等,我是否需要在 * 前面指定一个数字?
- haskell - Haskell - 生成长度为 k 的子集
- java - Java 堆排序和计数排序返回 false
- c# - 来自 Axios 405 或 415 错误的 Vue.js 和 .NET WEBAPI2 POST
- docker - 使用 docker 镜像设置 Keycloak SSL
- python - 查找熊猫中最长列的长度
- reactjs - 你如何在打字稿中注释一个未命名的箭头函数
- symlink - 为什么 Snakemake 看不到符号链接文件?