public \Joomla\CMS\MVC\Model\ModelInterface
createModel
(mixed $name, mixed $prefix = '', array $config = [])
/**
* Method to load and return a model object.
*
* @param string $name The name of the model.
* @param string $prefix Optional model prefix.
* @param array $config Optional configuration array for the model.
*
* @return ModelInterface The model object
*
* @since 3.10.0
* @throws \Exception
*/
public function createModel($name, $prefix = '', array $config = [])
{
// Clean the parameters
$name = preg_replace('/[^A-Z0-9_]/i', '', $name);
$prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
if (!$prefix) {
@trigger_error(sprintf('Calling %s() without a prefix is deprecated.', __METHOD__), E_USER_DEPRECATED);
$prefix = Factory::getApplication()->getName();
}
$className = $this->getClassName('Model\\' . ucfirst($name) . 'Model', $prefix);
if (!$className) {
return null;
}
$model = new $className($config, $this);
$this->setFormFactoryOnObject($model);
$this->setDispatcherOnObject($model);
return $model;
}