Answer the question
In order to leave comments, you need to log in
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');
<?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>';
}
} ?>
Answer the question
In order to leave comments, you need to log in
load related data with joinWith and then choose what you need
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question