This is an old revision of the document!
All models in Rack applications extend from the abstract <php>Model</php> class, defined in include/models/Model.class.php. This class provides a basic implementation for CRUD (create, read, update, and delete) functionality for a single database table. It utalizes the PDO
prepared statements to construct queries to help preventing SQL injections.
A <php>Model</php> object should never be manually created, as Rack provide a function <php>get_model($name)</php> in include/init.php that creates an instance of a <php>Model</php> object for you when need it. The following snippet demonstrates its use:
<PHP> $model = get_model('Registration'); $registrations = $model→get(); </PHP>
Basic queries can be executed using the functions <php>get</php>, <php>create</php>, <php>update</php> and <php>delete</php> or their by_id counterparts. The <php>create</php> and <php>update</php> functions accept a list with <php>'fieldname'⇒'value'</php> pairs that should be used to modify the database.
The <php>get</php>, <php>update</php> and <php>delete</php> functions also accept an array with filter conditions. These conditions will be appended to the query and multiple conditions will be joined with AND. In this array, filter conditions should be specified as <php>'fieldname__function' ⇒ $value</php>.
Supported comparison functions are:
=) another value.<>) another value.<) another value.⇐) another value.>) another value.>=) another value.LIKE '%value%' ''). Note that ''% and _ will not be automatically escaped.NULL (if <php>'fieldisnull'⇒true</php>) or not NULL (if <php>'fieldisnull'⇒false</php>). If the comparison function is omitted (<php>'field' ⇒ $value</php>), the default of eq is used.