ModelBase API

From Warwick Student Cinema
Jump to: navigation, search

An API Reference for classes that are imbued with ModelBase/SuperClass awesomeness.

PLEASE NOTE: This reference is very incomplete at the moment. Additions are being made as convenient. Though the API is fairly fixed, changes may be made without notice, so please be sure to read commit logs on bazaar regularly, as these are much more up to date than this page will be.

Static Methods

get

ModelBase ModelBase::get( mixed $primarykey ) ModelBase ModelBase::get( Array $searchparameters )

Possibly the most important method on the class, use this to retrieve a single object from the database. You can either pass the objects primary key (usually the ID) or you can pass an array containing key/value pairs corresponding to fields and desired values. Note that if the specified parameters do not identify a single unique object, an exception will be thrown. If you wish to retrieve several objects based on a common parameter, use getSet.

Film::get(47); Film::get( Array( 'shortname' => 'inception' ) );


getSet

Collection<ModelBase> ModelBase::getSet( Array $searchparameters, [ Array $order = Array() ], [ integer $limit = 0 ], [ integer $start = 0 ])

Used to retrieve a Collection of objects with the specified parameters. This will always return a Collection, whether or not any objects actually matched the specified parameters.

You must specify at least one field/value pair in $searchparamaters. If you wish to retrieve all objects, use getAll.

$order allows you to order the objects in the collection. It should be an array containing fields to order by as keys, and "ASC" or "DSC" as values. You CANNOT order by fields that are other ModelBase objects, only basic types, such as integer or string.

$limit allows you to limit the number of objects retrieved. It should be an integer greater than 0. A limit of 0 will result in unlimited results.

$start allows you to "skip" a number of objects. It should be an integer greater than 0. A start value of 0 will result in no "skipping".

$films_in_2009 = Film::getSet( Array ( 'year' => 2009 ) );

getAll

Collection<ModelBase> ModelBase::getAll( [ Array $order = Array() ], [ integer $limit = 0 ], [ integer $start = 0 ])

Similar to getSet, except that all objects are retrieved, rather than a subset. The $order, $limit and $start parameters act as in getSet.

$five_latest_news = News::getAll( Array( 'time'=>'DSC' ), 5);