Skip to content
Mo McRoberts edited this page Aug 7, 2011 · 3 revisions

Obtains an instance of one of [[Model]]'s descendants.

Synopsis

uses('model');

public static function Model [[Model]]::getInstance(array [in,optional] $args = null)

Description

If $args['class'] is not set, Model::getInstance() will immediately return null. Otherwise, an instance of the named class will be obtained, and its constructorModel::__construct will be invoked, passing $args. Descendants should override Model::getInstance() to set $args['class'] to the name of the class if it's not set. Descendants should, if possible, ensure that $args['db'] is set to a database connection IRI which can be passed to [[DBCore::connect]](). The combination of $args['class'] and $args['db'] are used to construct a key into the shared instance list. When a new instance is constructed, it is stored with this key in the list. If an entry with the key is already present, it will be returned and no new instance will be created.

Parameters

Name Direction Type Description
$args in,optional array Initialisation parameter array.

Return Value

On success, returns an instance of a descendant of [[Model]].

Clone this wiki locally