In my CodeIgniter project, one of my textbox field values is not inserting into db.
How to pass value from view to controller and vice-versa?
View Code (Here we enter the Ex-showromm Price,suppose 1500
)
When we hit Bill button, the value has to enter into db and and print it as a bill.
<?php
$total = 0;
$actual_price = 0;
if (count($list_product) > 0) {
foreach ($list_product as $key => $item) {
$total += $item['salePrice'];
?>
<tr>
<td bgcolor="#CCCCCC"> <?= $item['model'] . " " . $item['variant'] ?>
<br /> <?= $item['vin'] ?> </td>
<td bgcolor="#CCCCCC">
<?= $item['saleQty'] ?></td>
<td colspan="2" bgcolor="#CCCCCC"><input type="text" name="price" id="price" size="13px"/></td>
<td colspan="2" bgcolor="#CCCCCC"><input type="text" name="actual_price" id="actual_price" size="13px"/></td>
</tr>
<?php
}
}
?>
<tr>
<td colspan="4" align="center" valign="middle" bgcolor="#E0DFE3" class="cont"> <input name="tot_price" type="hidden" id="tot_price" size="50" value="<?=$total?>" /></td>
<td colspan="4" align="center" valign="middle" bgcolor="#E0DFE3" class="cont"> <input name="actual_price" type="hidden" id="actual_price" size="50" value="<?=$actual_price?>" /></td>
Bill View
The value from the database has been passed to a variable in the report
To pass a value to the view, you add it to an array and pass it to the view like so:
$Data['Pies'] = array('Cherry', 'Key Lime');
$Data['Cakes'] = array('Funfetti');
$Data['Paperplates'] = true;
$this->load->view('picnic', $Data);
CodeIgniter automatically unpacks the data on the view side, so you access it like so:
The first pie is <?=$Pies[0] ?>
<?php if ($Paperplates) { ?>
Don't bring plates <?php
} else { ?>
Bring plates please
<?php }
will print:
The first pie is Cherry
Don't bring plates
Regarding returning values to the controller: you don't, at least not the way you're thinking. In order to get variables back you'll need them to be sent from the browser using a POST
or GET
request.
I suggest you start off by reading the CodeIgniter User Guide.