gpt4 book ai didi

php - Yii2在gridview中显示序列化数据

转载 作者:行者123 更新时间:2023-11-29 16:39:06 25 4
gpt4 key购买 nike

我有一些以序列化格式存储的数据。

我可以提取数据并将其显示在登录用户的 View 中,如下所示:

$user_id = Yii::$app->user->identity->id;
$kids=unserialize($model->kids);
$children =\app\models\UserChildren::find()->where(['user_id' =>$user_id])->andwhere(['id'=>$kids])->all();
?>
<?php foreach ($children as $child): ?>
<table class="table table-bordered table-hover">
<tr>
<th><?php echo Yii::t('app', 'Kids Name')?> : </th>
<td><?php echo $child->child_name?> </td>
<th><?php echo Yii::t('app', 'Kids Birth Date')?> : </th>
<td><?php echo $child->child_birth_date?> </td>
<th><?php echo Yii::t('app', 'Kids Gender')?> : </th><td><?php echo $child->child_gender?> </td>
</tr>
</table>
<?php endforeach; ?>

child 数据存储在订单表中,如下所示,该表链接到表 userchildren。

s:0:"";
a:4:{i:0;s:2:"10";i:1;s:2:"11";i:2;s:2:"25";i:3;s:2:"26";}
a:2:{i:0;s:2:"10";i:1;s:2:"11";}

我尝试在 gridview 中显示相同的内容,但不知道如何实现这一点:

例如,如果我正在使用

[
'label'=> 'Child',
'value' => function($data){
return $data->order->kids;
}
],

我得到的数据与我所显示的相同。我也尝试过 foreach,但我得到了无效的参数 foreach。

最佳答案

不确定我是否做对了,但它似乎有正确的数据。

我使用的代码如下:

[
'label'=> 'Child',
'value' => function($data){
$kids=((unserialize($data->order->kids)));
$children1=ArrayHelper::map(\app\models\UserChildren::find()->where(['id'=>$kids])->all(),'id','child_name');
return implode(', ',$children1);

}
],

关于php - Yii2在gridview中显示序列化数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53437854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com