/**
* Typical view method for MVC based architecture
*
* This function is provide as a default implementation, in most cases
* you will need to override it in your own controllers.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link InputFilter::clean()}.
*
* @return static A \JControllerLegacy object to support chaining.
*
* @since 3.0
* @throws \Exception
*/
public function display($cachable = false, $urlparams = array())
{
$document = $this->app->getDocument();
$viewType = $document->getType();
$viewName = $this->input->get('view', $this->default_view);
$viewLayout = $this->input->get('layout', 'default', 'string');
$view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout));
// Get/Create the model
if ($model = $this->getModel($viewName, '', array('base_path' => $this->basePath))) {
// Push the model into the view (as default)
$view->setModel($model, true);
}
$view->document = $document;
// Display the view
if ($cachable && $viewType !== 'feed' && Factory::getApplication()->get('caching') >= 1) {
$option = $this->input->get('option');
if (\is_array($urlparams)) {
$this->app = Factory::getApplication();
if (!empty($this->app->registeredurlparams)) {
$registeredurlparams = $this->app->registeredurlparams;
} else {
$registeredurlparams = new \stdClass();
}
foreach ($urlparams as $key => $value) {
// Add your safe URL parameters with variable type as value {@see InputFilter::clean()}.
$registeredurlparams->{$key} = $value;
}
$this->app->registeredurlparams = $registeredurlparams;
}
try {
/** @var \Joomla\CMS\Cache\Controller\ViewController $cache */
$cache = Factory::getCache($option, 'view');
$cache->get($view, 'display');
} catch (CacheExceptionInterface $exception) {
$view->display();
}
} else {
$view->display();
}
return $this;
}