model
From SkyPHP
The aql class uses models to make database interaction more convenient.
Contents |
Parts of a model
Each model has the following parts:
- aql statement
- form
- required fields
- insert & update triggers
- validation (not model-specific, shared by any model that uses the same db field)
What is a model used for?
- Select data from the database [see aql::select()]
- Modify the select query with the clause array
- Ability to query multi-dimensional recordsets
- Display an html data grid [see aql::grid()]
- Easily build listing pages and profile pages (Content Management System)
- Save data to multiple tables and automatically save foreign key references [see aql::save()]
Example model folder
Let's take a look at the "person" model. Normally, you should name our model the same as its primary table.
- /models/person/person_aql.php
- /models/person/person_form.php
- /models/person/person_form.css (optional)
- /models/person/person_form.js (optional)
- /models/person/person_insert.php (optional)
- /models/person/person_update.php (optional)
Notes
If you join a second table to the primary table in the model, do not name the model with both table names.
Example:
We have a model named client_person because there is a table with that name.
But if you were to simply join the person table to the client table, still use the primary table (client in this case) as the name for the model.
