Base Database Model

It returns a Model object, always creating it.

  • string $type - The model type to instantiate
  • string $prefix - Prefix for the model class name. Optional.
  • array $config - Configuration array for model. Optional.
  • return \JModelLegacy|boolean - A \JModelLegacy instance or false on failure
public static function getInstance($type, $prefix = '', $config = array())
{
$type = preg_replace('/[^A-Z0-9_\.-]/i', '', $type);
$modelClass = $prefix . ucfirst($type);

if (!class_exists($modelClass))
{
jimport('joomla.filesystem.path');
$path = \JPath::find(self::addIncludePath(null, $prefix), self::_createFileName('model', array('name' => $type)));

if (!$path)
{
$path = \JPath::find(self::addIncludePath(null, ''), self::_createFileName('model', array('name' => $type)));
}

if (!$path)
{
return false;
}

require_once $path;

if (!class_exists($modelClass))
{
\JLog::add(\JText::sprintf('JLIB_APPLICATION_ERROR_MODELCLASS_NOT_FOUND', $modelClass), \JLog::WARNING, 'jerror');

return false;
}
}

return new $modelClass($config);
}