N
N
nikitalolo2016-12-26 16:12:00
Yii
nikitalolo, 2016-12-26 16:12:00

Yii2 How to make a table in a view with two foreach loops?

Function from the controller. Plates aorder and acustomer tied in the model.

public function actionIndex()
    {	
    	$model = new Aorder();
    	$aorder = Aorder::find()->asArray()->all();
    	$acustomer = Acustomer::find()->asArray()->all();
    	
        return $this->render('index', [
        	'aorder' => $aorder,	
      'model' => $model,
        	'acustomer' => $acustomer,	
        ]);  }

A piece of table code in a view. I wrote the first cycle for displaying fields from the first table, but how to write the second cycle correctly? If immediately after the first cycle there is another one, then it will write the remaining fields in one line of the table, several names, telephone numbers, etc. at once.
<tbody>
    <?php foreach($aorder as $item) { ?>
                        <tr>
                            <td><?= $item['id']; ?></td>
                            <td><?= $item['notified']; ?></td>
    <?php } ?>                  
                            <td><?= $item['customer']; ?></td>
                            <td><?= $item['phone']; ?></td>
                            <td><?= $item['inbox']; ?></td>  
                        </tr>
                    </tbody>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-12-26
@slo_nik

Good afternoon.
What for?!! Link between models, link data by id, get all data in one request and
use gridview

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question