public \Joomla\CMS\MVC\Model\BaseDatabaseModel|bool
getModel
(mixed $name = '', mixed $prefix = '', mixed $config = array())
/**
* Method to get a model object, loading it if required.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return BaseDatabaseModel|boolean Model object on success; otherwise false on failure.
*
* @since 3.0
*/
public function getModel($name = '', $prefix = '', $config = array())
{
if (empty($name)) {
$name = $this->getName();
}
if (!$prefix) {
if ($this->factory instanceof LegacyFactory) {
$prefix = $this->model_prefix;
} elseif (!empty($config['base_path']) && strpos(Path::clean($config['base_path']), JPATH_ADMINISTRATOR) === 0) {
$prefix = 'Administrator';
} else {
$prefix = $this->app->getName();
}
}
if ($model = $this->createModel($name, $prefix, $config)) {
// Task is a reserved state
$model->setState('task', $this->task);
// We don't have the concept on a menu tree in the api app, so skip setting it's information and
// return early
if ($this->app->isClient('api')) {
return $model;
}
// Let's get the application object and set menu information if it's available
$menu = Factory::getApplication()->getMenu();
if (\is_object($menu) && ($item = $menu->getActive())) {
$params = $menu->getParams($item->id);
// Set default state data
$model->setState('parameters.menu', $params);
}
}
return $model;
}