API15:JModel/getInstance
From Joomla! Documentation
Description
Returns a reference to the a Model object, always creating it
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
& getInstance($type, $prefix= '', $config=array())
| Parameter Name | Default Value | Description |
|---|---|---|
| $type | The model type to instantiate | |
| $prefix | Prefix for the model class name. Optional. | |
| $config | array() | Configuration array for model. Optional. |
Returns
mixed A model object, or false on failure
Defined in
libraries/joomla/application/component/model.php
Importing
jimport( 'joomla.application.component.model' );
Source Body
function &getInstance( $type, $prefix = '', $config = array() )
{
$type = preg_replace('/[^A-Z0-9_\.-]/i', '', $type);
$modelClass = $prefix.ucfirst($type);
$result = false;
if (!class_exists( $modelClass ))
{
jimport('joomla.filesystem.path');
$path = JPath::find(
JModel::addIncludePath(),
JModel::_createFileName( 'model', array( 'name' => $type))
);
if ($path)
{
require_once $path;
if (!class_exists( $modelClass ))
{
JError::raiseWarning( 0, 'Model class ' . $modelClass . ' not found in file.' );
return $result;
}
}
else return $result;
}
$result = new $modelClass($config);
return $result;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples