Hello, I am trying to create a session array every time I enter the controller, a new row is added to my array and it is displayed in the view. Something like a web shopping cart
my controller
public function PedidoAction($SEART_CODIGO) {
$seart_articulo = SeartArticulo::findFirstBySEART_CODIGO($SEART_CODIGO);
if (!$seart_articulo) {
$this->flash->error("Articulo No encontrado");
$this->dispatcher->forward(array(
'controller' => "carrito",
'action' => 'carrito'
));
return;
}
if ($this->session->has("id")) {
$_SESSION['id']++;
} else {
$this->session->set('id',0);
}
$id=$_SESSION['id'];
$this->session->set('DETALLECODIGO[]', $seart_articulo->SEART_CODIGO);
$this->session->set('DETALLENOMBRE[]', $seart_articulo->SEART_DETALLE);
$this->session->set('DETALLEPRECIO[]', $seart_articulo->SEART_PRECIOX);
$this->session->set('DETALLEIVA[]', $seart_articulo->SEART_DETALLE);
$this->session->set('DETALLECANTID[]', '1');
$this->session->set('DETALLETOTAL[]', $seart_articulo->SEART_PRECIOX);
}
And what I want to show in my view
<table class="table" table-bordered>
<!--table lista/table-row-group-striped-->
<thead>
<tr>
<th>
</th>
<th>Cant</th>
<th>Descripción</th>
<th>Iva</th>
<th>Precio</th>
<th>Total</th>
<th>Quitar</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_SESSION["DETALLECODIGO"])) {
$totalcoste = 0;
$Total = 0;
$n=count($_SESSION['DETALLECODIGO']);
echo $n;
echo $_SESSION['id'];
for ($i=0; $i<=$_SESSION['id']; $i++) {
echo "<td>". $i."</td>
<td> ". $this->session->get('DETALLECODIGO'.[$i])."</td>
<td>". $this->session->get('DETALLENOMBRE'.[$i])."</td>
<td>". $this->session->get('DETALLECANTID'.[$i])." </td>
<td>". $this->session->get('DETALLEIVA'.[$i])." </td>
<td>". $this->session->get('DETALLEPRECIO'.[$i])." </td>
<th>Quitar</th>";
}
}
?>
<tr>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="10"><strong>Cantidad:</strong> <span id="span_cantidad">0</span> Items.</td>
</tr>
</tfoot>
</table>
But nothing is displayed using $ id and if I use count () only one record is displayed, the array is not incremented. What is the problem?