I have a question about filling a table through an array with a foreach.
If I do it without a function, it does show me the expected result, but what I want is to use it as a function. For the moment I left it like this:
<?php require_once "../controller/usuarios_controller.php"; ?>
<table align="center" border="1">
<thead>
<td align="center"><strong>ID</strong></td>
<td align="center"><strong>USUARIO</strong></td>
<td align="center"><strong>CONTRASEÑA</strong></td>
<td align="center"><strong>DEPARTAMENTO</strong></td>
<td align="center"><strong>PRIVILEGIO</strong></td>
</thead>
<?php $datos = get_usuarios(); ?>
<?php foreach ($datos as $dato):?>
<tr>
<td align="center"><?php echo $dato["id"]; ?></td>
<td align="center"><?php echo $dato["usuario"]; ?></td>
<td align="center"><?php echo $dato["contrasena"]; ?></td>
<td align="center"><?php echo $dato["departamento"]; ?></td>
<td align="center"><?php echo $dato["privilegio"]; ?></td>
<td style="width:150px;">
<a href="adm/editar.php?id=<?php echo $dato["id"];?>">Editar</a>
<!-- <a class="<?php //echo $pagina == 'editar' ? 'active' : ''; ?>" href="views/editar.php?p=editar&id=<?php //echo $dato["id"];?>" >Editar</a>-->
<a class="<?php echo $pagina == 'editar' ? 'active' : ''; ?>" href="?p=editar&id=<?php echo $dato["id"];?>">EDITAR</a>
<a href="#" id="del-<?php echo $dato["id"];?>">Eliminar</a>
<script>
$("#del-"+<?php echo $dato["id"];?>).click(function(e){
e.preventDefault();
p = confirm("¿Está seguro que desea eliminar al Usuario?");
if(p){
window.location="?p=eliminar&id="+<?php echo $dato["id"];?>;
}
});
</script>
</td>
</tr>
<?php endforeach;?>
</table>
Note that I'm calling the controller that has the function and% $datos
assigned get_usuarios();
.
But nothing happens, still does not show me the table filled. The file where I have the function get_usuarios();
is like this:
<?php
//Llamada al modelo
require_once("../model/usuarios_model.php");
class usuarios_controller{
function get_usuarios(){
$per=new usuarios_model();
$datos=$per->get_usuarios();
//Llamada a la vista
require_once("../view/adm/usuarios_view.phtml");
}
}
?>
The model does not have any faults since I have tried it with different cases, it is only the controller that does not return anything in sight. Even putting the return $datos;
still does not send anything.
Could you explain it to me?