Chyrp

Model

The basis for the Models system.

Summary
Model The basis for the Models system.
Variables
$loaded_models Caches every loaded module into an array of results.
Functions
grab Grabs a single model from the database.
search Returns an array of model objects that are found by the $options array.
delete Deletes a given object.  Calls the “delete_(model)” trigger with the objects ID.

Variables

$loaded_models

static $loaded_models

Caches every loaded module into an array of results.

Functions

grab

protected static function grab( $model,   
$id,   
$options  =  array() )

Grabs a single model from the database.

Parameters

$model The instantiated model class to pass the object to (e.g.  Post).
$id The ID of the model to grab.  Can be null.
$options An array of options, mostly SQL things.

Options

select What to grab from the table.  (modelname)s by default.
from Which table(s) to grab from?  (modelname)s.* by default.
left_join A LEFT JOIN associative array.  Example: array(“table” => “foo”, “where” => “foo = :bar”)
where A string or array of conditions.  array(“__(modelname)s.id = :id”) by default.
params An array of parameters to pass to PDO.  array(“:id” => $id) by default.
group A string or array of “GROUP BY” conditions.
order What to order the SQL result by.  __(modelname)s.id DESC by default.
offset Offset for SQL query.
read_from An array to read from instead of performing another query.

search

protected static function search( $model,   
$options  =  array(),
$options_for_object  =  array() )

Returns an array of model objects that are found by the $options array.

Parameters

$options An array of options, mostly SQL things.
$options_for_object An array of options for the instantiation of the model.

Options

select What to grab from the table.  (modelname)s by default.
from Which table(s) to grab from?  (modelname)s.* by default.
left_join A LEFT JOIN associative array.  Example: array(“table” => “foo”, “where” => “foo = :bar”)
where A string or array of conditions.  array(“__(modelname)s.id = :id”) by default.
params An array of parameters to pass to PDO.  array(“:id” => $id) by default.
group A string or array of “GROUP BY” conditions.
order What to order the SQL result by.  __(modelname)s.id DESC by default.
offset Offset for SQL query.
limit Limit for SQL query.

See Also

Model.grab

delete

Deletes a given object.  Calls the “delete_(model)” trigger with the objects ID.

Parameters

$model The model name.
$id The ID of the object to delete.