sena / nogal.se
Nogal (Student Edition) - This is an ORM implementation in PHP7 based on DAO to be used in the learning environments of the National Learning Service - SENA in Colombia.
Requires
- php: >=7.0.0
This package is auto-updated.
Last update: 2025-04-06 18:43:48 UTC
README
It is a tiny implementation of the PHP7 ORM programming model based on DAO (Data Access Object) for use in the learning environments of the National Learning Service - SENA in Colombia.
Installation
For you to be able to use Nogal SE in your project, you must have the Composer tool installed.
composer require sena/nogal.se
Estructura del modelo
Nogal (Edición Estudiante) propone la siguiente estructura.
+-------------------- | model/ |-- base/ |---- UserBase.php |-- User.php +--------------------
Para poder explicar lo anterior debemos partir de que usaremos la siguiente estructura SQL para la tabla User.
CREATE TABLE DbUser ( Id int, Nick varchar(20), Password varchar(32), Actived boolean DEFAULT true, Created_at timestamp DEFAULT NOW() );
Archivo User.php
El siguiente código sería entonces el contenido del archivo User.php
<?php namespace MyApp\model; use MyApp\model\base\UserBase; class User extends UserBase { }
En estos archivos se ubicaría la lógica del negocio que tenga que ver con la tabla User, por ejemplo: necesito consultar el id de un usuario.
<?php namespace MyApp\model; use MyApp\model\base\UserBase; class User extends UserBase { public function SearchIdByUser() { $sql = 'SELECT Id FROM DbUser WHERE Nick = :nick'; $this->SetDbParam(':nick', $this->getNick(), \PDO::PARAM_STR); $data = $this->Query($sql); if (count($data) > 0) { return $data; } else { return false; } } }
Archivo UserBase.php
Este archivo contiene la estructura base de la tabla User y podemos expresarla de la siguiente forma: