-
Notifications
You must be signed in to change notification settings - Fork 0
model
Alan Smith edited this page Jul 5, 2011
·
2 revisions
The 'M' in MVC.
Defines a model at runtime allowing for models to be used without the need to create a class for each one.
| name | String | Name for the new model. |
| parent | String | The class the model should inherit from. (Default: AN_Model) |
Executes a (prepared) query and returns an array of models. Substitutes #table in the query with the name of the table. Any arguments beyond $query are substituted into the query.
<?php $user = User::query('SELECT FROM #table WHERE id=?', 10); ?>
| class | String | Class of the model. |
| query | String | SQL query. |
{Bool | Array}
False if query was not successfully executed, otherwise models from query.
Creates a row in the database with $data and returns the new model.
<?php $user = User::create(array('name' => 'Skrat', 'email' => 'skrat19@gmail.com')); ?>
| class | String | Class of the model. |
| data | Array | Data to be saved. |
{Object}
The model that was used to save the data. If the 'errors' property is empty the save was successful.
Updates row based on given condition(s).
<?php User::update(array('name' => 'Skrat', 'email' => 'skrat19@gmail.com'), 'id = ?', 10); ?>
| class | String | Class of the model. |
| value | Array | Value(s) to update. |
| condition | String | Condition(s) to limit the update to. |
{Bool}
False if data was unsuccessfully updated, otherwise true.
Delete row(s) with given condition(s).
<?php User::delete('id = ?', 10); ?>
| class | String | Class of the model. |
| condition | String | Condition(s) to limit the delete to. |
{Bool}
True if row(s) were deleted.