A
A
agent11562017-02-01 12:32:28
Yii
agent1156, 2017-02-01 12:32:28

How to do data output interleaving?

base1::find()->all();
base2::find()=>all();
And here html view
base1->title
base2->title
How to properly set up a cycle?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-02-01
@webinar

for example like this:

$arr = [];
$arr[] = MyModelOne::find()->limit(20)->asArray()->all();
$arr[] = MyModelSecond::find()->limit(20)->asArray()->all();
for($i = 0; $i < 20; $i++){
  if(isset($arr[0][$i]['title']) and isset($arr[1][$i]['title'])){
    echo $arr[0][$i]['title'];
    echo $arr[1][$i]['title'];
  }else{
    break;
  }
}

It could be simpler, but it's clearer. If you need to periodically do such nonsense, then it is better to take out the logic in MyDataProvider

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question