Download the PHP package 4k1r0/ormega without Composer
On this page you can find all versions of the php package 4k1r0/ormega. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package ormega
Ormega
Basic ORM for MySQL with classes generator directly from database
! Non CodeIgniter projects !
This ORM use Codeigniter Querybuilder so there's a standalone CI Querybuilder integreted with.
For codeigniter projects see here.
Install with composer
composer require 4k1r0/ormega
Model Generation
How to
Generated classes
This will create a dir {namespace}
in ./{path}
If I run the generator from /var/www/myproject/
whith
Will result in :
'Enum' is explained below.
'Entity' and 'Query' dir contains one empty php class for each table parsed with the generator and a 'base' directory.
These classes inherits from the one inside the base directory. They're empty to allow custom methods override.
They will not being erased if you restart the generation.
The "true" classes are in 'base' directories.
They must no be manually modified because a new file is wrote at each generation.
Custom methods
In these "empty" classes you're free to redefine every method.
You can add whatever you want in setters, getters, or even save method.
Or create customs queries (override find()
) or filters.
Enum
Enums are specials models created from tables named 'enum[...]' and are designed to contains CONSTANTS.
These tables must have only 3 columns : 'id', 'label', 'constant'
If you want to add a constant, you will have to restart the generation.
Example :
Table enumgender
id | label | constant |
---|---|---|
1 | man gender id | MAN |
2 | woman gender id | WOMAN |
Can be used like this
This allow a more readable code than hardcode the man ID.
The 'label' column is used as a description.
The code generated will look like this
There's also a set of methods within :
Usage
Init
This will add an autoloader for generated models.
Manipulate, insert or update
There's a setter and a getter for every table's columns.
Setters have an automatic data check based on column's type and length.
Ex : a mysql tinyint(1) will be converted to php boolean
This check throw a InvalidArgumentException.
Select multiple
::create()
is a shortcut for $oUserQuery = new \Ormega\Query\User();
Select one
Results
Usage : Foreign keys
The generator detects foreign keys and add an attribute for each in generated models.
So you can directly set the referenced Ormega entity model instead of foreign ID.
User | Profil |
---|---|
id | id |
login | #fk_user_id |
_FK1 userid reference User.id
Tips : If you modify both User and Profil entity, only one save is necessary on Profil entity.
Model generated :