Yii2 display serialized data in gridview
I have some data stored in serialized format.
I can pull the data and show it in view like this for the logged in user:
$user_id = Yii::$app->user->identity->id;
$kids=unserialize($model->kids);
$children =appmodelsUserChildren::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; ?>
The kids data is stored in order table like this, which is linked to the table 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";}
I have tried to display the same in gridview, but couldn't make out how I can achieve this:
like for example if I am using
[
'label'=> 'Child',
'value' => function($data){
return $data->order->kids;
}
],
I am getting the same data as I have shown.
I also tried foreach, but I am getting invalid argument foreach.
php mysql yii2
add a comment |
I have some data stored in serialized format.
I can pull the data and show it in view like this for the logged in user:
$user_id = Yii::$app->user->identity->id;
$kids=unserialize($model->kids);
$children =appmodelsUserChildren::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; ?>
The kids data is stored in order table like this, which is linked to the table 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";}
I have tried to display the same in gridview, but couldn't make out how I can achieve this:
like for example if I am using
[
'label'=> 'Child',
'value' => function($data){
return $data->order->kids;
}
],
I am getting the same data as I have shown.
I also tried foreach, but I am getting invalid argument foreach.
php mysql yii2
add a comment |
I have some data stored in serialized format.
I can pull the data and show it in view like this for the logged in user:
$user_id = Yii::$app->user->identity->id;
$kids=unserialize($model->kids);
$children =appmodelsUserChildren::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; ?>
The kids data is stored in order table like this, which is linked to the table 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";}
I have tried to display the same in gridview, but couldn't make out how I can achieve this:
like for example if I am using
[
'label'=> 'Child',
'value' => function($data){
return $data->order->kids;
}
],
I am getting the same data as I have shown.
I also tried foreach, but I am getting invalid argument foreach.
php mysql yii2
I have some data stored in serialized format.
I can pull the data and show it in view like this for the logged in user:
$user_id = Yii::$app->user->identity->id;
$kids=unserialize($model->kids);
$children =appmodelsUserChildren::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; ?>
The kids data is stored in order table like this, which is linked to the table 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";}
I have tried to display the same in gridview, but couldn't make out how I can achieve this:
like for example if I am using
[
'label'=> 'Child',
'value' => function($data){
return $data->order->kids;
}
],
I am getting the same data as I have shown.
I also tried foreach, but I am getting invalid argument foreach.
php mysql yii2
php mysql yii2
asked Nov 22 '18 at 20:52
JoshiJoshi
1,53651840
1,53651840
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Not sure If I have done correctly, but it appears to have the correct data.
The code I am using is like below:
[
'label'=> 'Child',
'value' => function($data){
$kids=((unserialize($data->order->kids)));
$children1=ArrayHelper::map(appmodelsUserChildren::find()->where(['id'=>$kids])->all(),'id','child_name');
return implode(', ',$children1);
}
],
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437854%2fyii2-display-serialized-data-in-gridview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Not sure If I have done correctly, but it appears to have the correct data.
The code I am using is like below:
[
'label'=> 'Child',
'value' => function($data){
$kids=((unserialize($data->order->kids)));
$children1=ArrayHelper::map(appmodelsUserChildren::find()->where(['id'=>$kids])->all(),'id','child_name');
return implode(', ',$children1);
}
],
add a comment |
Not sure If I have done correctly, but it appears to have the correct data.
The code I am using is like below:
[
'label'=> 'Child',
'value' => function($data){
$kids=((unserialize($data->order->kids)));
$children1=ArrayHelper::map(appmodelsUserChildren::find()->where(['id'=>$kids])->all(),'id','child_name');
return implode(', ',$children1);
}
],
add a comment |
Not sure If I have done correctly, but it appears to have the correct data.
The code I am using is like below:
[
'label'=> 'Child',
'value' => function($data){
$kids=((unserialize($data->order->kids)));
$children1=ArrayHelper::map(appmodelsUserChildren::find()->where(['id'=>$kids])->all(),'id','child_name');
return implode(', ',$children1);
}
],
Not sure If I have done correctly, but it appears to have the correct data.
The code I am using is like below:
[
'label'=> 'Child',
'value' => function($data){
$kids=((unserialize($data->order->kids)));
$children1=ArrayHelper::map(appmodelsUserChildren::find()->where(['id'=>$kids])->all(),'id','child_name');
return implode(', ',$children1);
}
],
answered Nov 22 '18 at 22:19
JoshiJoshi
1,53651840
1,53651840
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437854%2fyii2-display-serialized-data-in-gridview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown