Base Controller

Method to get a model object, loading it if required.

  • string $name - The model name. Optional.
  • string $prefix - The class prefix. Optional.
  • array $config - Configuration array for model. Optional
  • return - \JModelLegacy|boolean Model object on success; otherwise false on failure.
public function getModel($name = '', $prefix = '', $config = array())
{
if (empty($name))
{
$name = $this->getName();
}

if (empty($prefix))
{
$prefix = $this->model_prefix;
}

if ($model = $this->createModel($name, $prefix, $config))
{
// Task is a reserved state
$model->setState('task', $this->task);

// Let's get the application object and set menu information if it's available
$menu = \JFactory::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;
}