H
H
hollanditkzn2017-10-03 11:24:20
Arrays
hollanditkzn, 2017-10-03 11:24:20

How to display data from linked table using Arrayelper::index?

My problem is that I could display the data so that they are grouped by date. I just don’t understand how to display data from related data
In the controller

$comment = Comment::find()->addSelect(['DATE(date) as just_date','TIME(date) as time','comment','id_user'])->where(['id_zakaz' => $id])->asArray()->all();
        $comment = ArrayHelper::index($comment, null, 'just_date');

And in the view
<?php foreach ($comment as $key=>$com){
                echo Yii::$app->formatter->asDate($key, 'php:j M Y').'<br>';
                foreach ($com as $value=>$name){
                    echo Yii::$app->formatter->asTime(ArrayHelper::getValue($name, 'time'), 'php:H:i').' '.ArrayHelper::getValue($name, 'comment').' '.ArrayHelper::getValue($name, 'id_user').'<br>';
                }
            } ?>

That is, I need id_user->idUser->name. Only I have an idea to make another request, but will it be logical to make another request in the request

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-10-03
@hollanditkzn

load related data with joinWith and then choose what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question