Skip to content
Alan Smith edited this page Jul 5, 2011 · 2 revisions

AN_Model

The 'M' in MVC.

defineModel

Defines a model at runtime allowing for models to be used without the need to create a class for each one.

Parameters

name String Name for the new model.
parent String The class the model should inherit from. (Default: AN_Model)

query

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); ?>

Parameters

class String Class of the model.
query String SQL query.

Return

{Bool | Array}

False if query was not successfully executed, otherwise models from query.

create

Creates a row in the database with $data and returns the new model.

<?php $user = User::create(array('name' => 'Skrat', 'email' => 'skrat19@gmail.com')); ?>

Parameters

class String Class of the model.
data Array Data to be saved.

Return

{Object}

The model that was used to save the data. If the 'errors' property is empty the save was successful.

update

Updates row based on given condition(s).

<?php User::update(array('name' => 'Skrat', 'email' => 'skrat19@gmail.com'), 'id = ?', 10); ?>

Parameters

class String Class of the model.
value Array Value(s) to update.
condition String Condition(s) to limit the update to.

Return

{Bool}

False if data was unsuccessfully updated, otherwise true.

delete

Delete row(s) with given condition(s).

<?php User::delete('id = ?', 10); ?>

Parameters

class String Class of the model.
condition String Condition(s) to limit the delete to.

Return

{Bool}

True if row(s) were deleted.

Clone this wiki locally