app/Models/AgendaModel.php
<?php
namespace App\Models;
use CodeIgniter\Model;
class AgendaModel extends Model
{
protected $table = 'contactos';
protected $primaryKey = 'id';
protected $allowedFields = ['id','nombre','apellidos','celular'];
public function getAll()
{
return $this->findAll();
}
}
app/Controllers/AgendaController.php
<?php
namespace App\Controllers;
use App\Models\AgendaModel;
class AgendaController extends BaseController
{
public function index()
{
$AgendaModel = new AgendaModel();
$data['agenda'] = $AgendaModel->getAll();
return view('agenda',$data);
}
}
app/Views/agenda.php
<h1>Agenda</h1> <table> <thead> <tr> <th>Id</th> <th>Nombre</th> <th>Apellidos</th> <th>Celular</th> </tr> </thead> <tbody> <?php foreach($agenda as $item): ?> <tr> <td> <?= $item['id'] ?> </td> <td> <?= $item['nombre'] ?> </td> <td> <?= $item['apellidos'] ?> </td> <td> <?= $item['celular'] ?> </td> </tr> <?php endforeach ?> </tbody> </table>
app/Config/Routes.php
$routes->get('/', 'AgendaController::index');
No hay comentarios.:
Publicar un comentario