Base Controller

It is a method to get a reference to the current view and load it if necessary.

  • string $name - The view name. Optional, defaults to the controller name.
  • string $type - The view type. Optional.
  • string $prefix - The class prefix. Optional.
  • array $config - Configuration array for view. Optional.
  • return \JViewLegacy - Reference to the view or an error.
public function getView($name = '', $type = '', $prefix = '', $config = array())
{
// @note We use self so we only access stuff in this class rather than in all classes.
if (!isset(self::$views))
{
self::$views = array();
}

if (empty($name))
{
$name = $this->getName();
}

if (empty($prefix))
{
$prefix = $this->getName() . 'View';
}

if (empty(self::$views[$name][$type][$prefix]))
{
if ($view = $this->createView($name, $prefix, $type, $config))
{
self::$views[$name][$type][$prefix] = & $view;
}
else
{
throw new \Exception(\JText::sprintf('JLIB_APPLICATION_ERROR_VIEW_NOT_FOUND', $name, $type, $prefix), 404);
}
}

return self::$views[$name][$type][$prefix];
}