Documentation

Start a Project

Naming conventions

  • Most of the names must be written in snake_case.
  • There are three types of property:
    • basic property: in a model or association, it is for example an int, a bool, a string ...
    • association property: in a Model instance, it is a property that contains a Model instance, an array of Model instances or an array of Association instances
    • associate property: in an Association instance, it is a property that contains a Model instance

    The names of the basic properties must match the names of the database fields.
    The names of the association fields must be suffixed with '_id' (ex: article_id).
    About the associations, the property name may be different than the field name (See $config['artefact_mapping_associations'] in ./application/config/config_artefact.php).

The database

The first step of a project is to create the database.
You can find an example for PostgreSQL here and for MySQL here.

The primary key of a Model must be named 'id'.
About a simple Model or abstract Model, it must be a 'SERIAL' for PostgreSQL and an 'INT AUTO_INCREMENT' for MySQL.
About a concrete Model, it must be a simple 'INT' and in addition to being a primary key, it is a foreign key referencing the primary key of the related abstract Model.

The primary key of an Association is a composite key, composed of the primary keys of the Models involved in the Association.
Each element of the composite key is a foreign key referencing the primary key of the related Model.

Instead of using the 'ENUM' field type, you should use the Enum_model concept (See Enum model).

The configuration

The main configuration file is ./application/config/config.php.
In addition to the CodeIgniter configuration items, you have to set the item $config['application_namespace'].
This item corresponds to the folder ./application.
It is used in the folder ./application/business for the models and the associations.
It can also be used if you create a folder in ./application, for example a folder 'utils'.

The Artefact configuration file is: ./application/config/config_artefact.php
There are three config items:

  • $config['artefact_data_conv']
    List all the database tables and define the type of each field
    The field types for PostgreSQL are:
    • pk
    • fk:table_name
    • pk_fk:table_name
    • enum_model_id:table_name
    • enum_type:enum_type_name (Not recommended)
    • int
    • float
    • string
    • bool
    • json
    • date
    • interval
    • time
    • timetz
    • timestamp
    • timestamptz

    The field types for MySQL are:
    • pk
    • fk:table_name
    • pk_fk:table_name
    • enum_model_id:table_name
    • int
    • float
    • string
    • bool
    • json
    • set
    • date
    • datetime
    • interval
    • time
    • timestamp
    • year
  • $config['artefact_mapping_models']
    List the models present in the folder ./application/business/models and related to a database table
    • If the table name matches the class name in lowercase, the key-value pair is:
      'Model_name' => [],
    • If the table name doesn't match the class name in lowercase, the key-value pair is:
      'Model_name' => ['table' => 'table_name'],
  • $config['artefact_mapping_associations']
    List the associations between the mapping models
    There are three types of association:
    • one-to-one
    • one-to-many
    • many-to-many

    Each array item defines an association.
    It is an array with at least an element whose key is 'associates'.
    If it is a many-to-many association, there is an element whose key is 'class' and optionally an element whose key is 'table' if the table name doesn't match the class name in lowercase.
    A many-to-many association involves two models or more, and each model must have a 'dimension' set to 'many'.

In the array $autoload['helper'] of the file ./application/config/autoload.php, you have to add 'pgsql' if your database is PostgreSQL or 'mysql' if it is MySQL.

The Model classes

The Model classes are located in the folder ./application/business/models.

The namespace is 'application_namespace\business\models' where application_namespace is the namespace set in $config['application_namespace'].

A Model class extends the Concorde\artefact\Model class.

If it is an abstract model, it uses the Concorde\artefact\Table_abstract_model_trait trait.

If it is a concrete model, it uses the Concorde\artefact\Table_concrete_model_trait trait.

The properties are 'private' and accessible through the getters/setters.

The names of the basic properties must match the names of the database fields.

The parameters of the constructor must be the basic properties and their names must match each other.

In the constructor, the association properties must be set to 'new Undefined()'.

The Association classes

The Association classes are located in the folder ./application/business/associations.

The namespace is 'application_namespace\business\associations' where application_namespace is the namespace set in $config['application_namespace'].

An Association class extends the Concorde\artefact\Association class and uses the Concorde\artefact\Table_association_trait trait.

The properties are 'private' and accessible through the getters/setters.

The names of the basic properties must match the names of the database fields.

The parameters of the constructor must be the basic properties and their names must match each other.

The name of an associate property must match the related 'reverse_property' item in $config['artefact_mapping_associations'].