【发布时间】:2018-01-17 10:07:00
【问题描述】:
我是 Yii2 的新手,不,我试图在视图中显示数据。我以前做过这样的(使用GridView):
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'car_id',
'value' => 'car.state_num'
],
[
'attribute' => 'driver_id',
'value' => 'driver.name'
],
'status',
'first_date',
'second_date',
// 'status',
// 'foto:ntext',
// 'description:ntext',
['class' => 'yii\grid\ActionColumn'],
],
]);
(它的视图显示了与“Driver”和“Car”表连接的“contract”表)
但现在我不会通过常见的引导表来执行此操作,如下所示:
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Car</th>
<th scope="col">Start</th>
<th scope="col">Finish</th>
<th scope="col">Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($dataProvider->getModels() as $item):?>
<tr>
<th scope="row">Order ID <?= $item->id ?> </th>
<td><?= $item->car_id ?></td>
<td><?= $item->first_date ?></td>
<td><?= $item->second_date ?></td>
<td><?= $item->status ?></td>
</tr>
<? endforeach; ?>
</tbody>
</table>
它也可以,但是 Car 的列显示 car_id.. 问题:我怎样才能将 car.state_num 用于在视图中显示它?
【问题讨论】:
标签: php yii2 frameworks