Yii2 display serialized data in gridview












0














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.










share|improve this question



























    0














    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.










    share|improve this question

























      0












      0








      0







      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 at 20:52









      Joshi

      1,52551739




      1,52551739
























          1 Answer
          1






          active

          oldest

          votes


















          0














          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);

          }
          ],





          share|improve this answer





















            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            0














            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);

            }
            ],





            share|improve this answer


























              0














              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);

              }
              ],





              share|improve this answer
























                0












                0








                0






                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);

                }
                ],





                share|improve this answer












                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);

                }
                ],






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 22:19









                Joshi

                1,52551739




                1,52551739






























                    draft saved

                    draft discarded




















































                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                    Alexandru Averescu

                    Trompette piccolo