[eluser]jstuardo[/eluser]
Hello !!
I have just started using CodeIgniter and I found the first strange problem.
Please, look at this code I have in a view:
Code:
foreach ($usuarios as $usuario)
$class_suffix = $ndx % 2 == 0 ? 'Inverse' : '';
echo " <tr>
<td class='tableRow'>$usuario->id</td>
<td class='tableRow'>$usuario->username<td>
<td class='tableRow'>$usuario->nombres</td>
<td class='tableRow'>$usuario->apellidos</td>
<td class='tableRow'>$usuario->email</td>
<td class='tableRow'>$usuario->fecha_registro</td>
<td class='tableRow'>$usuario->fecha_visita</td>
<td class='tableRow'>$usuario->activo</td>
</tr>";
where $usuarios is a view variable assigned with "$data['usuarios'] = $this->Usuario_model->get_usuarios($start, $reg_x_pag);" in controller.
Initially, $usuarios is empty.
When I run the page, I get several errors concerning $usuario declaration:
------
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: usuario
Filename: views/lista_usuarios.php
Line Number: 50
------
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/lista_usuarios.php
Line Number: 50
------
Where line number 50 is:
Code:
<td class='tableRow'>$usuario->id</td>
Well. The strange thing is that if I comment the line "$class_suffix = $ndx % 2 == 0 ? 'Inverse' : '';", the errors are gone.
Any help will be greatly appreciated. PHP automatically declare variables so I cannot realize why this error is happening and dependant on a line that doesn't even use the mentioned variable.
Thanks
Jaime