I have array of data that gets input from several models using findbysql. The view renders perfectly in this format
#|building_id | tariff_id | fee_id
[list=1]
[*]|3 | 1 | 3
[*]|2 | 2 |5
[*]|5 | 4 | 2
[*]|1 | 3 | 6
[/list]
The issue is how do i save all this array data rendered by the view using submit button.
The model is InspectionMapping. I think my issue is with the controller, I dont know how to go about it since am new to yii2
[b]
Controller[/b]
public function actionMappingadmin()
{
$sql = "SELECT distinct b.building_id, b.building_name, t.tariff_id, f.fee_id
FROM building b INNER JOIN building_tariff t ON (t.tariff_id = b.tariff_id)
INNER JOIN fee f ON (t.tariff_id = f.tariff_id)
/*WHERE b.building_id NOT IN (select building_id from inspection_booking) */
WHERE RAND() > 0.667
ORDER BY building_name
";
$inspectionmapping = InspectionMapping::findBySql($sql)->all();
$inspectionmapping->building_id=$data['building_id']
$inspectionmapping->tariff_id=$data['tariff_id']
$inspectionmapping->fee_id=$data['fee_id'];
}
}
return $this->render('mappingadmin', [
'inspectionmapping' => $inspectionmapping,
]);
}
View
<div class="mapping-form">
<?php $form = ActiveForm::begin(['id' => 'mapping-form']); ?>
<h1>Mapping for Inspection</h1>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>Building</th>
<th>Tariff</th>
<th>Fee</th>
</tr>
</thead>
<tbody>
<?php $i = 1;
foreach($inspectionmapping as $data): ?>
<tr>
<td><?php echo $i++;?></td>
<td class="tbl_column_name"><?=$data->building_id;?></td>
<td class="tbl_column_name"><?=$data->tariff_id;?></td>
<td class="tbl_column_name"><?=$data->fee_id;?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
<div class="form-group">
<div class="col-xs-12 col-sm-2 col-lg-2">
<button id="but1" class="btn btn-primary btn-block btn-lg" name="continue" type="submit">Save</button>
</div>
</div>
<?php ActiveForm::end(); ?>
</div> <!-- /.End of Inspection Sheet -->
</div> <!-- /.End of col-xs-12 col-lg-12 -->
I have rendered the view.
Please I need to save this batch of array data