public \Joomla\CMS\MVC\View\ViewInterface
getView
(mixed $name = '', mixed $type = '', mixed $prefix = '', mixed $config = array())
/**
* Method to get a reference to the current view and load it if necessary.
*
* @param string $name The view name. Optional, defaults to the controller name.
* @param string $type The view type. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for view. Optional.
*
* @return ViewInterface Reference to the view or an error.
*
* @since 3.0
* @throws \Exception
*/
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 (!$prefix) {
if ($this->factory instanceof LegacyFactory) {
$prefix = $this->getName() . 'View';
} elseif (!empty($config['base_path']) && strpos(Path::clean($config['base_path']), JPATH_ADMINISTRATOR) === 0) {
$prefix = 'Administrator';
} else {
$prefix = $this->app->getName();
}
}
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(Text::sprintf('JLIB_APPLICATION_ERROR_VIEW_NOT_FOUND', $name, $type, $prefix), 404);
}
}
return self::$views[$name][$type][$prefix];
}